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
Auto file forward bot with python

Auto-File-Forward-Bot Auto file forward bot. Without Admin Permission in FROM_CHANNEL Only Give Permission In your Telegram Personal Channel Please fo

Milas 1 Oct 15, 2021
Your custom slash commands Discord bot!

Slashy - Your custom slash-commands bot Hey, I'm Slashy - your friendly neighborhood custom-command bot! The code for this bot exists because I'm like

Omar Zunic 8 Dec 20, 2022
A Telegram bot to download youtube playlists and upload them to telegram. (may be slow becoz youtube limitations)

YTPlaylistDL 📛 A Telegram bot to download youtube playlists and upload them to telegram. (may be slow becoz youtube limitations) 🎯 Follow me and sta

Anjana Madu 43 Dec 28, 2022
Prisma Cloud utility scripts, and a Python SDK for Prisma Cloud APIs.

pcs-toolbox Prisma Cloud utility scripts, and a Python SDK for Prisma Cloud APIs. Table of Contents Support Setup Configuration Script Usage CSPM Scri

Palo Alto Networks 34 Dec 15, 2022
Easy to use API Wrapper for somerandomapi.ml.

Overview somerandomapi is an API Wrapper for some-random-api.ml Examples Asynchronous from somerandomapi import Animal import asyncio async def main

Myxi 1 Dec 31, 2021
A Python wrapper for the DeepL API

deepl.py A Python wrapper for the DeepL API installing Install and update using pip: pip install deepl.py A simple example. # Sync Sample import deep

grarich 18 Dec 12, 2022
Often discord bots just die, and we hardly find one that is durable

Muitas vezes bots do discord simplesmente morrem, e dificilmente achamos um que seja durável. Então porque não ter um próprio para emergências? Como c

Guilherme Almeida 3 Dec 06, 2022
Easily report Instagram pages and close the page

Program Features - 📌 Delete target post on Instagram. - 📌 Delete Media Target post on Instagram - 📌 Complete deletion of the target account on Inst

hack4lx 11 Nov 25, 2022
A script that writes automatic instagram comments under a post

Send automatic messages under a post on instagram Instagram will rate limit you after some time. From there on you can only post 1 comment every 40 se

Maximilian Freitag 3 Apr 28, 2022
Api REST para gerenciamento de cashback.

Documentação API para gerenciamento de cashback - MaisTODOS Features Em construção... Tecnologias utilizadas Back end Python 3.8.10 Django REST Framew

Alinne Grazielle 2 Jan 22, 2022
Another Autoscaler is a Kubernetes controller that automatically starts, stops, or restarts pods from a deployment at a specified time using a cron annotation.

Another Autoscaler Another Autoscaler is a Kubernetes controller that automatically starts, stops, or restarts pods from a deployment at a specified t

Diego Najar 66 Nov 19, 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 03, 2022
Rocks vc Userbot: A Telegram Bot Project That's Allow You To Play Audio And Video Music On Telegram Voice Chat Group

⭐️ Rocks VC Userbot ⭐️ Telegram Userbot To Play Audio And Video Song On VC Chat

Dr Asad Ali 10 Jul 18, 2022
this is an op music pyrogram music bot.

amanrajputpytgcallmusic this is an op music pyrogram music bot..... this bot user music bot can play music without being admin...... TG-MusicPlayer A

2 Dec 27, 2021
This is Source Code of PdiskUploaderBot

PdiskUploaderBot This is the source code of PdiskUploaderBot. And the developer of this bot is AJTimePyro, His Telegram Channel & Group. You can use t

Abhijeet 8 Oct 20, 2022
M3U Playlist for free TV channels

Free TV This is an M3U playlist for free TV channels around the World. Either free locally (over the air): Or free on the Internet: Plex TV Pluto TV P

Free TV 964 Jan 08, 2023
Visualize size of directories, s3 buckets.

Dir Sizer This is a work in progress, right now consider this an Alpha or Proof of Concept level. dir_sizer is a utility to visualize the size of a di

Scott Seligman 13 Dec 08, 2022
Anti Spam/NSFW Telegram Bot Written In Python With Pyrogram.

✨ SpamProtectionRobot ✨ Anti Spam/NSFW Telegram Bot Written In Python With Pyrogram. Requirements Python = 3.7 Install Locally Or On A VPS $ git clon

Akshay Rajput 46 Dec 13, 2022
Fetch torrent links from nyaa, according to releases by smoke index.

Nyaa - Smoke's index torrent fetcher Description This script parses the local (or online) anime release index (csv format) made by Big Smoke. And uses

Dinank 21 Jun 08, 2022
Stackoverflow Telegram Bot With Python

Template for Telegram Bot Template to create a telegram bot in python. How to Run Set your telegram bot token as environment variable TELEGRAM_BOT_TOK

PyTopia 10 Mar 07, 2022