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
42-event-notifier - 42 Event notifier using 42API and Github Actions

42 Event Notifier 42서울 Agenda에 새로운 이벤트가 등록되면 알려드립니다! 현재는 Github Issue로 등록되므로 상단

6 May 16, 2022
QuickStart specific rules for cfn-python-lint

AWS Quick Start cfn-lint rules This repo provides CloudFormation linting rules specific to AWS Quick Start guidelines, for more information see the Co

AWS Quick Start 12 Jul 30, 2022
Easy Discord Webhook Token Grabber!

Easy Discord Webhook Token Grabber!

†† 27 Jun 01, 2022
Get charts, top artists and top songs WITHOUT LastFM API

LastFM Get charts, top artists and top songs WITHOUT LastFM API Usage Get stats (charts) We provide many filters and options to customize. Geo filter

4 Feb 11, 2022
Acid's Utilities is a bot for my Discord server that alerts when I go live, welcomes new users, has some awesome games and so much more!

Acid's Utilities Acid's Utilities is a bot for my Discord server that alerts when I go live, welcomes new users, has some awesome games and so much mo

AcidFilms (Fin Stuart) 3 Nov 19, 2021
An unofficial wrapper for Engineer Man's Piston API

Pistonpy Pistonpy is an API wrapper for the Piston code execution engine by Engineer Man. Key Features Simple modern and efficient Pythonic API using

AalbatrossGuy 4 Jan 03, 2022
Discord Webhook Proxy for Roblox payloads.

RoProxy A Discord webhook proxy passthrough for roblox. Setup Your port and endpoint are in the config.json, make sure both app.py and config.json are

PythonSerious 2 Nov 05, 2021
Automation for grabbing keys from a Linux host. Useful during red team exercises to quickly help assess what access to a Linux host can lead to.

keygrabber Automation for grabbing keys from a Linux host. This can be helpful during red team exercises when you gain access to a Linux host and want

Cedric Owens 14 Sep 27, 2022
A free and open-source discord webhook spammer.

Discord-Webhook-Spammer A free and open-source discord webhook spammer. Usage Depending on your python installation your commands may vary. Below are

3 Sep 08, 2021
Python lib to control HottoH based stove devices

Project desciption This library can be used to discuss with HootoH based stove devices Actually tested and validated with a CMG Drum stove. To use thi

3 May 16, 2022
Python SDK for the Buycoins API.

This library provides easy access to the Buycoins API using the Python programming language. It provides all the feature of the API so that you don't need to interact with the API directly. This libr

Musa Rasheed 48 May 04, 2022
Senexia - A powerful telegram bot to manage your groups as effectively as possible

⚡ Kenechi bot ⚡ A Powerful, Smart And Simple Group Manager ... Written with AioG

Akhi 2 Jan 11, 2022
Automatically Message From Discord Account

Discord-AutoMessage A robust and versatile solution for automated social interactions HOW TO INSTALL Open cmd cd into your project directory Run the f

13 Jul 11, 2022
A full-featured Python wrapper for the Onfleet API.

UPDATE: Please use Onfleet's wrapper instead. This repository is not maintained. https://github.com/onfleet/pyonfleet --- Python-Onfleet   python-onfl

Lionheart Software 11 Jan 13, 2022
Widevine MPD Content Downloader & Decryptor

Widevine-DL Encrypted MPD Manifest Content Downloader + Decryptor (not a Widevine Key Extractor!) Requirements ffmpeg, yt-dlp, aria2, widevine-l3-decr

Vank0n (SJJeon) 170 Dec 30, 2022
A Telegram bot to all media and documents files to web link .

FileStreamBot A Telegram bot to all media and documents files to web link . Report a Bug | Request Feature 🍁 About This Bot : This bot will give you

Code X Mania 129 Jan 03, 2023
Telegram Group Management Bot based on phython !!!

How to setup/deploy. For easiest way to deploy this Bot click on the below button Mᴀᴅᴇ Bʏ Sᴜᴘᴘᴏʀᴛ Sᴏᴜʀᴄᴇ Find This Bot on Telegram A modular Telegram

Mukesh Solanki 5 Nov 17, 2021
A multi-password‌ cracking tool that can help you hack facebook accounts very quickly

FbCracker This is a multi-password‌ cracking tool that can help you hack facebook accounts very quickly. Facebook Hacking Tool Installation On Termux

ReD H4CkeR 9 Nov 16, 2022
A simple telegram bot to download from Zee5 links

Zee5 Downloader If you find any bugs, report at @TroJanzSupport My Features: 👉 Upload as file/video from any NON-DRM Zee5 link 👉 Permanent thumbnail

TroJanzHEX 95 Dec 20, 2022
A simple python oriented telegram bot to give out creative font style's

Font-Bot A simple python oriented telegram bot to give out creative font style's REQUIREMENTS tgcrypto pyrogram==1.2.9 Installation Fork this reposito

BL4CK H47 4 Jan 30, 2022