{"id":17796621,"url":"https://github.com/ire4ever1190/dimscmd","last_synced_at":"2025-03-17T02:31:42.114Z","repository":{"id":47687579,"uuid":"322481874","full_name":"ire4ever1190/dimscmd","owner":"ire4ever1190","description":"A command handler for dimscord","archived":false,"fork":false,"pushed_at":"2024-08-16T06:43:30.000Z","size":363,"stargazers_count":29,"open_issues_count":6,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T16:56:07.683Z","etag":null,"topics":["discord","hacktoberfest","library","nim"],"latest_commit_sha":null,"homepage":"","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ire4ever1190.png","metadata":{"files":{"readme":"readme.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-18T03:49:20.000Z","updated_at":"2025-01-16T10:41:58.000Z","dependencies_parsed_at":"2022-09-23T20:50:52.941Z","dependency_job_id":"aff48d08-0c2b-4202-8202-e9c861b54b6f","html_url":"https://github.com/ire4ever1190/dimscmd","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ire4ever1190%2Fdimscmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ire4ever1190%2Fdimscmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ire4ever1190%2Fdimscmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ire4ever1190%2Fdimscmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ire4ever1190","download_url":"https://codeload.github.com/ire4ever1190/dimscmd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841125,"owners_count":20356440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","hacktoberfest","library","nim"],"created_at":"2024-10-27T11:47:10.371Z","updated_at":"2025-03-17T02:31:41.624Z","avatar_url":"https://github.com/ire4ever1190.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"***********************\nDimscord Command Handler\n***********************\n\n.. image:: https://github.com/ire4ever1190/dimscmd/workflows/Tests/badge.svg\n    :alt: Test status\n\nThis is built on top of the amazing `dimscord library \u003chttps://github.com/krisppurg/dimscord\u003e`_ so if you have any questions about using dimscord or dimscmd then join the `dimscord discord \u003chttps://discord.com/invite/dimscord\u003e`_ (please send questions about dimscmd in the #dimscmd channel)\n\n`Docs available here \u003chttps://ire4ever1190.github.io/dimscmd/dimscmd\u003e`_\n\nInstall\n====\n\n.. code-block::\n\n    nimble install dimscmd\n\nSetup\n=====\n\nFirst create the handler object\n\n.. code-block:: nim\n\n    import dimscord\n    import dimscmd\n    let discord = newDiscordClient(token)\n    var cmd = discord.newHandler() # Must be var\n\nThen add the handler into your message_create event using `handleMessage()` proc. It is in this proc\nthat you can define the prefix (or prefixes) that you want the bot to handle\n\n.. code-block:: nim\n\n    proc messageCreate (s: Shard, msg: Message) {.event(discord).} =\n        discard await cmd.handleMessage(\"$$\", s, msg) # Returns true if a command was handled\n        # You can also pass in a list of prefixes\n        # discard await cmd.handleMessage(@[\"$$\", \"\u0026\"], s, msg)\n\nUse\n====\n\nCommands are created using Nim's do notation\n\n.. code-block:: nim\n\n    cmd.addChat(\"ping\") do ():\n        discard await discord.api.sendMessage(msg.channelID, \"pong\") # Message is passed to the proc as msg\n\n    # If msg is not to your fancy then you can change it\n    cmd.addChat(\"ping\") do (m: Message):\n        discard await discord.api.sendMessage(m.channelID, \"pong\")\n\nBut you are probably wondering \"can I add parameters to my commands?\" and the answer is yes and it is very easy.\nJust add parameters to the signature and you're off\n\n.. code-block:: nim\n\n    cmd.addChat(\"echo\") do (word: string):\n        discard await discord.api.sendMessage(m.channelID, word)\n\n    # You can add as many types as you want\n    cmd.addChat(\"repeat\") do (word: string, times: int):\n        for i in 0..\u003ctimes:\n            discard await discord.api.sendMessage(m.channelID, word)\n\n\nCurrent supported types are (don't think you want any other types)\n    - string\n    - bool\n    - int\n    - enums\n    - discord user\n    - discard channel\n    - discord role\n\nseq[T] and Option[T] for those types are also supported\n\n.. code-block:: nim\n\n    cmd.addChat(\"sum\") do (nums: seq[int]):\n        var sum = 0\n        for num in nums:\n            sum += num\n        discard await discord.api.sendMessage(m.channelID, $sum)\n\n.. code-block:: nim\n\n    cmd.addChat(\"kill\") do (user: Option[User]):\n        if user.isSome():\n            discard await discord.api.sendMessage(msg.channelID, \"Killing them...\")\n            # TODO, see if this is legal before implementing.\n        else:\n            discard await discord.api.sendMessage(msg.channelID, \"I can't kill nobody\")\n\nDimscmd does do other stuff like generate a help message automatically when the user sends the message \"help\" after\nthe prefix. This can be overrided by defining a help command yourself\n\n.. code-block:: nim\n\n    cmd.addChat(\"help\") do (commandName: Option[string]): # parameters can be whatever you want\n        if commandName.isSome():\n            # Send help message for that command\n        else:\n            # Say something helpful\n\n\nSlash commands\n====\n\nSlash commands are also supported with this library and are declared in a similar fashion. There are some things to\nbe mindful of though when using slash commands such as\n - names cannot contain capital letters\n - This library currently doesn't provide any help with creating interaction responses\n\nFirst add the handler into the interaction create event like with messages and also\nadd the command register into the on ready event\n\n.. code-block:: nim\n\n    proc onReady (s: Shard, r: Ready) {.event(discord).} =\n        await cmd.registerCommands()\n\n    proc interactionCreate (s: Shard, i: Interaction) {.event(discord).} =\n        discard await cmd.handleInteraction(s, i)\n\nThen add your slash commands\n\n.. code-block:: nim\n\n    cmd.addSlash(\"add\") do (a: int, b: int):\n        ## Adds two numbers\n        await discord.api.interactionResponseMessage(i.id, i.token,\n            kind = irtChannelMessageWithSource,\n            response = InteractionCallbackDataMessage(\n                content: fmt\"{a} + {b} = {a + b}\"\n            )\n        )\n\nSlash commands support the types supported (including enums) with the exception of seq[T]\n\n\nDuring testing it is recommend that you set a specific guild so that slash commands\nwill be registered instantly (instead of waiting an hour for them to be register globally)\n\n.. code-block:: nim\n\n    cmd.addSlash(\"add\", guildID = \"123456789\") do (a: int, b: int):\n        ## Adds to numbers\n        ...\n\n    # I recommend setting up something like this\n    when defined(debug):\n        const defaultGuildID = \"3456789\"\n    else:\n        const defaultGuildID = \"\" # Global\n\n    # This will set the default guild for all slash commands\n    let cmd = discord.newHandler(defaultGuildID = defaultGuildID)\n\n    cmd.addSlash(\"add\") do (a: int, b: int):\n        ## Adds to numbers\n        ...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fire4ever1190%2Fdimscmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fire4ever1190%2Fdimscmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fire4ever1190%2Fdimscmd/lists"}