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
Pincer-ext-commands - A simple, lightweight package for pincer prefixed commands

pincer.ext.commands A reimagining of pincer's command system and bot system. Ins

Vincent 2 Jan 11, 2022
API to retrieve the number of grades on the OGE website (Website listing the grades of students) to know if a new grade is available. If a new grade has been entered, the program sends a notification e-mail with the subject.

OGE-ESIREM-API Introduction API to retrieve the number of grades on the OGE website (Website listing the grades of students) to know if a new grade is

Benjamin Milhet 5 Apr 27, 2022
A Python wrapper for discord slash-commands, designed to extend discord.py.

dislash.py An extending library for discord.py that allows to build awesome slash-commands. ⭐

null 173 Dec 19, 2022
Attempting to create a framework for Discord Slash commands... yes

discord_slash.py Attempting to create a framework for Discord Slash commands... yes Installation pip install slashpy Documentation Coming soon™ Why is

AlexFlipnote 11 Mar 24, 2021
Terminal Bot which will Execute your Commands From telegram bot!

Terminal-Bot see this bot alive: https://t.me/HerokuTerminal_Bot With this bot you can execute system commands on your server. how to config? clone or

Moshe 41 Dec 9, 2022
An example of using discordpy 2.0.0a to create a bot that supports slash commands

DpySlashBotExample An example of using discordpy 2.0.0a to create a bot that supports slash commands. This is not a fully complete bot, just an exampl

null 7 Oct 17, 2022
Discord music bot using discord.py, slash commands, and yt-dlp.

bop Discord music bot using discord.py, slash commands, and yt-dlp. Features Play music from YouTube videos and playlists Queue system with shuffle Sk

Hizkia Felix 3 Aug 11, 2022
A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create custom messages by telling the bot with Commands.

A discord Server Bot made with Python, This bot helps people feel better by inspiring them with motivational quotes or by responding with a great message, also the users of the server can create custom messages by telling the bot with Commands.

Aran 1 Oct 13, 2021
A python library for creating Slack slash commands using AWS Lambda Functions

slashbot Slashbot makes it easy to create slash commands using AWS Lambda functions. These can be handy for creating a secure way to execute automated

Eric Brassell 17 Oct 21, 2022
A simple python discord bot with commands for moderation and utility.

Discord Bot A simple python discord bot with commands for moderation, utility and fun. Moderation $kick <user> <reason> - Kick a user from the server

syn 3 Feb 6, 2022
Free and Open Source Channel/Group Voice chat music player for telegram ❤️ with button support Heroku Commands

ZeusMusic Requirements ?? FFmpeg NodeJS nodesource.com Python 3.7 or higher PyTgCalls MongoDB 2nd Telegram Account (needed for userbot) ?? Get SESSION

ZeusNetwork 4 Jan 3, 2022
Open Source Discord bot with many cool features like Weather, Balance, Avatar, User, Server, RP-commands, Gif search, YouTube search, VK post search etc.

Сокобот Дискорд бот с открытым исходным кодом. Содержит в себе экономику, полезные команды (!аватар, !юзер, !сервер и тд.), рп-команды (!обнять, !глад

serverok 2 Jan 16, 2022
An example Music Bot written in Disnake and uses slash commands to operate.

Music Bot An example music bot that is written in Disnake [Maintained discord.py Fork] Disnake Disnake is a maintained and updated fork of discord.py.

null 6 Jan 8, 2022
Automatically send commands to send Twitch followers to any Twitch account.

Automatically send commands to send Twitch followers to any Twitch account. You just need to be in a Twitch follow bot Discord server!

Thomas Keig 6 Nov 27, 2022
A Discord Bot - has a few commands. Built using python - Discord.py - RIP.

Discord_Bot A Discord Bot has been built here. It is capable of running a few commands. The below present screenshot should suffice in terms of explai

Manab Kumar Biswas 1 May 22, 2022
Simple python program to execute terminal commands on telegram chats directly.

Small python code which can be handy when using telegram and you don't want to use VPS again and again. By configuring the code in your VPS, You can execute commands and get your output within telegram. It can also be very useful in performing Recon.

Veshraj Ghimire 34 Dec 5, 2022
A Slash Commands Discord Bot created using Pycord!

Hey, I am Slash Bot. A Bot which works with Slash Commands! Prerequisites Python 3+ Check out. the requirements.txt and install all the pakages. Insta

Saumya Patel 18 Nov 15, 2022
Aqui está disponível GRATUITAMENTE, um bot de discord feito em python, saiba que, terá que criar seu bot como aplicação, e utilizar seu próprio token, e lembrando, é um bot básico, não se utiliza Cogs nem slash commands nele!

BotDiscordPython Aqui está disponível GRATUITAMENTE, um bot de discord feito em python, saiba que, terá que criar seu bot como aplicação, e utilizar s

Matheus Muguet 4 Feb 5, 2022
A simple Discord Bot created for basic functionality and fun chat commands for use in a private server.

LoveAndChaos-Bot v0.1.0 LoveAndChaos-Bot is a Discord Bot specifically designed for a private server; this bot is merely a test and a method to expose

Morgan Rose 1 Dec 12, 2021