Shedding a new skin on Dis-Snek's commands.

Overview

PyPI Downloads Code style: black

Molter - WIP

Shedding a new skin on Dis-Snek's commands.

Currently, its goals are to make message commands more similar to discord.py's message commands.

Installing

pip install molter

Example

Load this as a normal scale in dis_snek

import dis_snek
import molter
from typing import Optional


class CommandTest(dis_snek.Scale):

    @molter.msg_command()
    async def test(
        self,
        ctx: dis_snek.MessageContext,
        a_num: int,
        a_user: Optional[dis_snek.Member],
        a_bool: bool,
    ):
        await ctx.message.reply(f"{a_num} {a_user} {a_bool}")


def setup(bot):
    CommandTest(bot)

Note

  • This project is a work in progress - it is very unstable and potentially very broken. Basic testing has been done, but more is still required.
  • Typing.Literal and discord.py's Greedy have not been added yet. Similar features to them are planned to be added in the future.
Comments
  • feat: basic help message

    feat: basic help message

    This is a basic implementation of a help command to tick off one of your points in #3.

    Pre-merge utilisation of this is fairly simple

    class bot(Snake):
        def __init__(sefl, ...):
            help = HelpCommand(self, show_params=True, ...)
            help.register()
    

    To modify it, pre-merge, i really think just overriding is the way to go. Post merge i would like to introduce some sort of client method to modify help.

    This pr is dependant on dev-latest of dis-snake. Specifically https://github.com/Discord-Snake-Pit/Dis-Snek/commit/af6402230b409be638f45e12f80710dc99e2efb2

    opened by LordOfPolls 5
  • feat: basic help message

    feat: basic help message

    Re-open of #5 due to unresolvable branch conflict issues.

    This is a basic implementation of a help command to tick off one of your points in #3.

    Pre-merge utilisation of this is fairly simple

    class bot(Snake):
        def __init__(sefl, ...):
            help = HelpCommand(self, show_params=True, ...)
            help.register()
    

    To modify it, pre-merge, i really think just overriding is the way to go. Post merge i would like to introduce some sort of client method to modify help.

    This pr is dependant on dev-latest of dis-snake. Specifically https://github.com/Discord-Snake-Pit/Dis-Snek/commit/af6402230b409be638f45e12f80710dc99e2efb2

    enhancement 
    opened by LordOfPolls 1
  • feat: annotation > converter specifiers

    feat: annotation > converter specifiers

    An idea discussed on the dis-snek server was the idea to allow normal annotations to be use in Molter commands by tying a converter to them. This is what is done for dis-snek objects, actually, but allowing user-defined "injections" would be nice as well.

    Take, for example:

    
    @molter.msg_command()
    @molter.register_converter(CustomClass, CustomClassConverter)
    async def test(ctx: Context, class_var: CustomClass):
        ...
    

    Molter would be able to take care of the conversion just with that decorator.

    This PR is not done and in fact is just a draft. Reviews and contributions are encouraged.

    enhancement 
    opened by AstreaTSS 1
  • [DISCUSSION] Parameter Analyzing and the Merge

    [DISCUSSION] Parameter Analyzing and the Merge

    This isn't quite about a bug or the like. Think of it like a subissue of #3, but it's just a design discussion that have to do with the merge:tm:.

    As of right now, molter (essentially) analyzes parameters (for its own use) upon function decoration. This may seem sane, but there is one issue: dealing with self parameters (or rather finding out when they're there and ignoring them if they are).

    self isn't exactly a special variable in Python - it can be named anything, and isn't typehinted or marked as anything special. We want to avoid it if it is there (it's always possible to declare a command in __main__, and is intended behavior), but... well, we can't. Not really.

    molter does the next best thing and checks if the function is "nested" - if it's in something, classes included. Based on that, we can theoretically ignore self if it is. However, this method uses a hack and is a hack, having many cases where this would fail. As such, another method is likely needed. Maybe.

    There aren't any better ways until molter is merged, but once it is...

    Solution 1

    Analyze the function as it is being added to the bot's dicts of prefix commands. As this is done with the context needed to determine if the command is in a scale (or in the bot class) or not, this is possible.

    The best way to do this is likely to add an extra argument to add_message_command that indicates if the underlying function has a self statement or not (defaulting to it not), and then running the parameter analyzing in the function itself. This also allows people adding their own commands manually to have some sort of control over that process, too.

    Basically:

    def add_message_command(command: MessageCommand, *, has_self: bool = False):
        command.parse_parameters(has_self=has_self)
        ... # rest of logic here
    
    # scales and in-bot commands can simply make has_self True when running that
    

    There is one drawback: if invalid parameters are passed (an invalid converter, etc.), then the user won't found out it's invalid until the bot is loaded. However, this method has the benefit of allowing all associate_converters to be associated before the command is parsed, meaning we don't have to dig into the parsed parameters to replace things as needed.

    Solution 2

    Analyze all parameters (minus whatever one's the first one) on function decoration. Then, if the command is being loaded in a place that indicates the function has self, edit the parameters list so that the first element is removed.

    This is very simple, in like with what dis-snek does, and allows for errors to happen pretty early on. However, this means that associated converters have to do what they currently do and dig into the current parameters to adjust them as needed, which is somewhat ugly. This also makes globally_associate_converter not be able to apply retroactively, and also makes it a pain to do if we do what Silasary mentioned here, as, well, we wouldn't get the bot's associated converters until after the parameters have been parsed and messed around (and so they would have to be messed around with *again).

    Conclusion

    I'm leaning towards solution 1 personally, but I'm curious to see what everyone else thinks. I also do wonder if it's even worth the pain when the hack works... fine in most cases. Again, I'm looking for ideas and feedback, so do say your thoughts!

    help wanted 
    opened by AstreaTSS 0
  • merge: dev > main

    merge: dev > main

    This will be accomplished via a force push due to their differing commit histories. This PR is more just a note that this will happen. A new version will be released soon after doing so to support dis-snek 8.0.0.

    Is waiting on #7 and #8.

    opened by AstreaTSS 0
  • merge: merge merge into dev

    merge: merge merge into dev

    Funny title, haha.

    With the merge to dis-snek basically being not very viable right now, I figured it would be a good idea just to merge everything from merge into dev. The branches don't really need to be separate, nor do I want to throw away the work done on merge.

    This will likely require force pushing and rebasing.

    opened by AstreaTSS 0
  • [FEAT] Merge with `dis-snek`

    [FEAT] Merge with `dis-snek`

    This was the end goal, after all. Fixes dis-snek's #392.

    Merging molter is not an easy task. Ideally, it would be done before the beta soft deadline, but if this is not complete, this should not hold dis-snek back from going into beta.

    In terms of molter itself, there's a few things that need to be finished up:

    • [x] Bug fixing, obviously. Not many people have used the advanced features, so that's something to consider.
    • [x] Making a help command. Technically, this isn't a strict requirement, but being honest, people who use message commands will want one - it's worth providing one under the ext namespace.
    • [x] Helper functions and properties, largely for:
      • [x] Allowing custom usage specifications instead of forcing people to use signature.
      • [x] Speaking of which, refactoring signature if possible.
      • [x] Probably more I can't think of quite yet. For Github's sake, this is going to be marked as done, but it might not be.
    • [x] At least finish the docstrings. Doing a whole page would be nice.
    • [ ] Subclassing BadArgument to have more specific errors. Is not strictly necessary to merge and may be ignored, but I'd prefer this being done.
    • [ ] Make invoked_name way better. It's, uh, a mess right now.
    • [x] Add command to Context in dis-snek itself.

    In terms of merging molter itself... yeah, that's going to be a doozy.

    • [x] A guide about how to use message commands would be a requirement at this point.
    • [x] Adjust Converter to either be not message command specific, or rename it to indicate it being so.
    • [x] File restructuring, separating message commands into its own file at the very least. I don't actually want to touch the BaseCommand too much.

    If anyone sees this and wants to help out, go ahead!

    help wanted 
    opened by AstreaTSS 11
Releases(v0.11.0)
  • v0.11.0(Apr 7, 2022)

    Oh lord is this update huge backend wise. Front-end wise, it's not horrible, but there's still a lot.

    And never mind on this being the last update... there's a lot that happened since then.

    What's Changed

    • FEAT💥: molter now uses dis-snek 8.0.0.
    • FEAT💥: Restructured and added channel converters. Some were removed/renamed in this process.
    • FEAT💥: MolterCommand.all_commands is now a frozenset instead of a tuple.
    • REFACTOR💥: MolterCommand.params has been renamed to MolterCommand.parameters.
    • FEAT: Added a basic help command for MolterCommands. (#8)
    • FEAT: Added register_converter to allow using normal annotations for commands while using Converters behind the scenes. (#7)
    • FEAT: MolterCommand.usage has been added, allowing you to specify how the command should be used if you don't like MolterCommand.signature.
    • FEAT: Make Converter's context Context instead of MessageContext so it has a chance of being used with other types of commands in the future.
    • FEAT: Make MolterCommand hashable.
    • FEAT/REFACTOR: Adjust parameter parsing to allow more control, allowing for MolterCommand.parse_parameters to be used by you if you need it.
    • REFACTOR: Much of the backend has changed to match up more closely with dis-snek's style.
    • REFACTOR: MolterCommand.signature has been redone. It may give slightly more accurate results.
    • DOCS: Added docstrings to many utility functions.
    • CI: pre-commit-related files were updated.

    New Contributors

    • @LordOfPolls made their first contribution in https://github.com/Discord-Snake-Pit/molter/pull/8

    Full Changelog: https://github.com/Discord-Snake-Pit/molter/compare/v0.9.1...v0.11.0

    Source code(tar.gz)
    Source code(zip)
  • v0.10.0(Mar 16, 2022)

    Minus bug fixes, this may be the second-to-final separated release of this version of molter. molter as an idea isn't exactly dead - I still want to go and see what I can do with slash commands and all - but it'll become more of a personal project that won't get merged with dis-snek ever rather than what it is now.

    What's Changed

    New Features

    • MolterSnake no longer rejects dis_snek.MessageCommand, and works with it and MolterCommands perfectly.
    • typing.Annotated support was added. molter assumes that it needs to use the second paramtere in the Annotation.
    • MessageConverter now uses a potentially faster method to get messages. At worst, it takes the same amount of time as the previous method.

    Bug Fixes

    • Arguments no longer get split at newlines.
    • MolterCommand.invoked_name now can have newlines if they were being used.
    • MolterCommand.get_command and MolterSnake.get_command work correctly with newlines now.
    • MolterCommand.remove_command no longer errors out with invalid names.
    • MolterCommand.qualified_name works correctly now.
    • MolterCommand.all_commands no longer errors out.

    Other

    • pre-commit's config was updated a bit.

    Full Changelog: https://github.com/Discord-Snake-Pit/molter/compare/v0.9.1...v0.10.0

    Source code(tar.gz)
    Source code(zip)
  • v0.9.1(Feb 27, 2022)

    Oops, haha.

    • Fix many converters erroring out due to incorrect getting/fetching.

    Full Changelog: https://github.com/Discord-Snake-Pit/molter/compare/v0.9.0...v0.9.1

    Source code(tar.gz)
    Source code(zip)
  • v0.9.0(Feb 27, 2022)

    This doesn't really feel like a major release, but semantic versioning is what it is because this update technically is breaking.

    • BREAKING: Upgrade to dis-snek 7.0.0, as it would have been annoying to support v6 and v7 at the same time.
      • No, this doesn't work with the latest dev version. A dev branch that closely follows dis-snek's dev branch is something I'm considering.
    • All converters that checked for an ID no longer check for an ID between 15-20 characters have been made so they only check for 15+ characters - who knows, maybe Discord will go over that limit.
    • Added a converter for dis_snek.Message, MessageConverter! This allows users to provide messages via a message link or a message ID, for example.

    Also, we're a part of the Snake-Pit organization now! Isn't that cool? Doesn't mean anything for this project beyond being officially recognized, though - merging with dis-snek isn't something that's going to be happening super soon.

    Full Changelog: https://github.com/Discord-Snake-Pit/molter/compare/v0.8.0...v0.9.0

    Source code(tar.gz)
    Source code(zip)
  • v0.8.0(Feb 22, 2022)

    An update after a while, woot!

    • BREAKING: Upgrade to dis-snek 6.0.0. There were some annoying bugs in 5.0.0.
      • This does not work with the latest dev version, or at least won't work correctly - sorry! It'll be fixed once the next version of dis-snek comes out.
    • BREAKING: VoiceChannelConverter has been changed to GuildVoiceConverter as you can't import dis_snek.VoiceChannel easily anyways, nor are you intended to.
    • BREAKING: Subcommands are now created with subcommand only rather than with command and its aliases. This is to be more consistent with dis-snek itself, especially with how it handles slash commands.
    • MolterCommand.signature is a thing! It's more or less exactly how discord.py did it - it's basically a way of getting a POSIX-like signature for a command's arguments.
    • MolterSnake.get_command(name) is a thing too! It allows you to get a command from its name, aliases or not, and even can go through subcommands.
    • Some fixes and adjustments here and there.

    Full Changelog: https://github.com/Astrea49/molter/compare/v0.7.0...v0.8.0

    Source code(tar.gz)
    Source code(zip)
  • v0.7.0(Feb 3, 2022)

    A small update, but hey, I'm back! Sorry, life got in the way. This update is really just about addressing dis_snek 0.5.0, which introduced a lot of breaking changes that needed to be accounted for.

    Updates

    • BREAKING: Upgraded to dis_snek 5.0.0. Older versions of dis_snek will no longer work.
      • EmojiConverter has been removed as Molter no longer supports versions below 5.0.0.
      • CustomEmojiConverter was changed to be faster if you have emoji caching on.
    • Molter now uses modern attr API names, attr.define and attr.field, over attr.s and attr.ib.

    New Contributors

    • @silasary made their first contribution in https://github.com/Astrea49/molter/pull/1! Thanks so much for this - it saved me quite a bit of time, even if it wasn't perfect.

    Full Changelog: https://github.com/Astrea49/molter/compare/v0.6.0...v0.7.0

    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Jan 14, 2022)

    Finally, subcommands!

    • Subcommands have been added! They do not require a different decorator - you can make any command a subcommand by doing base_cmd.command(), and it'll work!
      • These do not work like discord.py subcommands, as you expect, and you shouldn't treat them like one. The base command will always be run if no subcommand is found, and base command checks, by default, are run before subcommand checks (in case you want to run just subcommand checks, you can use hierarchical_checking on the base command).
    • MolterScale has been removed. Try to use MolterSnake if you can - it works great!
    • Fixed Molter with the the master/dev branches of Dis-Snek. This was caused by Emoji being renamed to PartialEmoji - Molter now automatically will detect which one to use!

    Full Changelog: https://github.com/Astrea49/molter/compare/v0.5.1...v0.6.0

    Source code(tar.gz)
    Source code(zip)
  • v0.5.1(Jan 9, 2022)

    A quick little bugfix.

    • Replaced a return with a continue in the two override classes, allowing for more than one alias and proper processing of Scales/commands in general.

    Full Changelog: https://github.com/Astrea49/molter/compare/v0.5.0...v0.5.1

    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Jan 9, 2022)

    We're slowly getting into phase 2 of Molter, where the features that require digging into Dis-Snek itself is being added.

    • Added aliases, working as they did in discord.py except that they must be a string. However, in order to use them, you must use:
    • Added MolterSnake and MolterScale, two classes that subclass Snake and Scale to add in alias support for each of the two classes. You must use one or the other - you cannot use both. You also MUST use them to use aliases.
    • Made name positional, while making everything else keyword-only for the decorator.
    • Fixed the message command decorator erroring out when neither a help or brief parameter were passed and the command lacked any docstrings of its own.

    Full Changelog: https://github.com/Astrea49/molter/compare/v0.4.0...v0.5.0

    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Dec 31, 2021)

    A very simple update, mainly to set out parts needed for the next part of molter and to show this project isn't dead.

    • Added some command parameters, like help text and a feature similar to discord.py's ignore_extra.
      • Note: these changes are simple, but they may break as I may have missed something. If so, sorry! I'll fix that ASAP.

    Full Changelog: https://github.com/Astrea49/molter/compare/v0.3.2...v0.4.0

    Source code(tar.gz)
    Source code(zip)
  • v0.3.2(Dec 22, 2021)

    • Bumped up minimum Dis-Snek version to 4.2.0. Technically, this is breaking, but I think anyone using this is already the latest version anyways.
    • Made MemberConverter be able to fetch users by user/nickname even if the guild is not chunked.

    Full Changelog: https://github.com/Astrea49/molter/compare/v0.3.1...v0.3.2

    Source code(tar.gz)
    Source code(zip)
  • v0.3.1(Dec 22, 2021)

    • Parse and check parameters on decoration assignment, not on first run of the command. This means errors with parameters are discovered as they are loaded in, not over and over again as the command is run.
    • Changed parameter-analyzing errors to ValueError rather than BadArgument.

    Full Changelog: https://github.com/Astrea49/molter/compare/v0.3.0...v0.3.1

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Dec 22, 2021)

    • Added Greedy converters! They mostly function the same as discord.py's Greedy, though they do not work in variable or keyword-only arguments.
    • ...that's it.

    Full Changelog: https://github.com/Astrea49/molter/compare/v0.2.0...v0.3.0

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Dec 21, 2021)

    • Added support for Literals! Only objects with types with a constructor that accepts one argument will work (the primitive data types like str and int work well with it, so something like Literal["e"] works right out of the box).
    • Fixed weirdness with how quoted arguments were handled.
    • Slightly clearer error message for Union-related errors.
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Dec 20, 2021)

    • Added proper support for variable arguments, handling type hints correctly.
    • Added support for inline advanced converters.
    • Fixed issues with Optionals at an end of a command.
    • Slight adjustments to error handling.

    Full Changelog: https://github.com/Astrea49/molter/compare/v0.0.2...v0.1.0

    Source code(tar.gz)
    Source code(zip)
  • v0.0.2(Dec 20, 2021)

    • Added support for | union syntax.
    • Display clearer error messages for error messages involving unions.
    • Fixed consume rest behavior.
    • Added proper error handling for functions with more than 2 arguments.
    • Added support for 0 argument functions.
    Source code(tar.gz)
    Source code(zip)
  • v0.0.1b(Dec 19, 2021)

Owner
Astrea
Just a random girl developing random things for random uses. Mainly just a lot of Discord bots, though. She/her, please!
Astrea
Discord group chat leaver.

Discord group chat leaver I know many people who have fallen victim to these weird group chat spammers including me. I made this script to help those

cliphd 3 Feb 27, 2022
Graviti-python-sdk - Graviti Data Platform Python SDK

Graviti Python SDK Graviti Python SDK is a python library to access Graviti Data

Graviti 13 Dec 15, 2022
A casino discord bot written in Python

Casino Bot Casino bot is a gambling discord bot I made for my friends. It is able to play blackjack, slots, flip a coin, and roll dice. It stores ever

Connor Swislow 27 Dec 30, 2022
Smilecreator4 - This site is for people who want to hack or want to learn it!

smilecreator4 This site is for people who want to hack or want to learn it! Furthermore, this program does not work without turning off Antivirus or W

1 Jan 04, 2022
Framework to collect and process weather data from wttr.in.

Weathercrawler Automatic extraction and processing framework for weather data from wttr.in Installation tested with: Python 3.7.3 Python 3.9.4 git clo

Maurice Günder 0 Jul 26, 2021
股票量化

StockQuant Gary-Hertel 请勿提交issue!可以加入交流群与其他朋友一起自学交流,加微信mzjimmy 一、配置文件的设置 启动框架需要先导入必要的模块,并且载入一次配置文件! 配置文件是一个json格式的文件config.json,在docs文件夹中有模板

218 Dec 25, 2022
Python client to do LispTick requests

lisptick-python LispTick Python client library It allows to send request and receive result from a LispTick server. Get a socket connection to a LispT

Kereon Intelligence 1 Oct 25, 2021
Media Replay Engine (MRE) is a framework to build automated video clipping and replay (highlight) generation pipelines for live and video-on-demand content.

Media Replay Engine (MRE) is a framework for building automated video clipping and replay (highlight) generation pipelines using AWS services for live

Amazon Web Services - Labs 30 Nov 29, 2022
Intelligent Trading Bot: Automatically generating signals and trading based on machine learning and feature engineering

Intelligent Trading Bot: Automatically generating signals and trading based on machine learning and feature engineering

Alexandr Savinov 326 Jan 03, 2023
Nft-maker - Create your own NFT!

nft-maker How to If you're going to use this program, change the pictures in the "images" folder. All images must be of the same resolution and size.

Georgii Arakelian 4 Mar 13, 2022
Simple Webhook Spammer with Optional Proxy Support

😎 �Simple Webhook Spammer with Optional Proxy Support:- [+] git clone https://g

Terminal1337 12 Sep 29, 2022
Python tool to Check running WebClient services on multiple targets based on @leechristensen

WebClient Service Scanner Python tool to Check running WebClient services on multiple targets based on @tifkin_ idea. This tool uses impacket project.

Pixis 153 Dec 28, 2022
PyManGenerator is a token generator for discord, it joins servers using webbot to automate everything

PyManGenerator is a token generator for discord, it joins servers using webbot to automate everything. Captcha can be done by itself unless you used your current IP Address more than once.

5 Nov 27, 2021
Mark Sullivan 66 Dec 13, 2022
Python On WhatsApp - Run your python codes on whatsapp along with talking to a chatbot

Python On WhatsApp Run your python codes on whatsapp along with talking to a chatbot This is a small python project to run python on whatsapp. and i c

Prajjwal Pathak 32 Dec 30, 2022
SpotPlay2YouPlay - Converts new additions to a Spotify playlist to a matching Youtube playlist

SpotPlay2YouPlay - Converts new additions to a Spotify playlist to a matching Youtube playlist, can also be configured to converting whole playlists with the refresh fun

9 Mar 06, 2022
A discord bot for tracking Iranian Minecraft servers and showing the statistics of them

A discord bot for tracking Iranian Minecraft servers and showing the statistics of them

MCTracker 20 Dec 30, 2022
Red-mail - Advanced email sending library for Python

Red Mail Next generation email sender What is it? Red Mail is an advanced email

Mikael Koli 313 Jan 08, 2023
Automatically updates the twitter banner with the images of 5 latest followers, using tweepy python

Auto twitter banner Automatically updates the twitter banner every few seconds with follower profile pics on it Here's how it looks! Installation git

Dhravya Shah 7 Jul 04, 2022
A slack bot that notifies you when a restaurant is available for orders

Slack Wolt Notifier A Slack bot that notifies you when a Wolt restaurant or venue is available for orders. How does it work? Slack supports bots that

Gil Matok 8 Oct 24, 2022