Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ire4ever1190/dimscmd

A command handler for dimscord
https://github.com/ire4ever1190/dimscmd

discord hacktoberfest library nim

Last synced: 11 days ago
JSON representation

A command handler for dimscord

Awesome Lists containing this project

README

        

***********************
Dimscord Command Handler
***********************

.. image:: https://github.com/ire4ever1190/dimscmd/workflows/Tests/badge.svg
:alt: Test status

This is built on top of the amazing `dimscord library `_ so if you have any questions about using dimscord or dimscmd then join the `dimscord discord `_ (please send questions about dimscmd in the #dimscmd channel)

`Docs available here `_

Install
====

.. code-block::

nimble install dimscmd

Setup
=====

First create the handler object

.. code-block:: nim

import dimscord
import dimscmd
let discord = newDiscordClient(token)
var cmd = discord.newHandler() # Must be var

Then add the handler into your message_create event using `handleMessage()` proc. It is in this proc
that you can define the prefix (or prefixes) that you want the bot to handle

.. code-block:: nim

proc messageCreate (s: Shard, msg: Message) {.event(discord).} =
discard await cmd.handleMessage("$$", s, msg) # Returns true if a command was handled
# You can also pass in a list of prefixes
# discard await cmd.handleMessage(@["$$", "&"], s, msg)

Use
====

Commands are created using Nim's do notation

.. code-block:: nim

cmd.addChat("ping") do ():
discard await discord.api.sendMessage(msg.channelID, "pong") # Message is passed to the proc as msg

# If msg is not to your fancy then you can change it
cmd.addChat("ping") do (m: Message):
discard await discord.api.sendMessage(m.channelID, "pong")

But you are probably wondering "can I add parameters to my commands?" and the answer is yes and it is very easy.
Just add parameters to the signature and you're off

.. code-block:: nim

cmd.addChat("echo") do (word: string):
discard await discord.api.sendMessage(m.channelID, word)

# You can add as many types as you want
cmd.addChat("repeat") do (word: string, times: int):
for i in 0..