dimscmd

Search:
  Source   Edit

Procs

proc addAlias(group: CommandGroup; commandName: string;
              aliases: openArray[string]) {....raises: [KeyError, ValueError],
    tags: [].}
Like addChatAlias or addSlashAlias except more generic

Example: cmd: -r:off --threads:off

import dimscord
let cmd = newDiscordClient("TOKEN").newHandler()
# Alias can be added like so
cmd.chatCommands.addAlias("ping", ["pi"])
cmd.slashCommands.addAlias("joke", ["funnyword"])
  Source   Edit
proc addChatAlias(router: CommandHandler; commandName: string;
                  aliases: openArray[string]) {....raises: [KeyError, ValueError],
    tags: [].}
Adds alternate names for a chat command command

Example: cmd: -r:off --threads:off

import dimscord
let cmd = newDiscordClient("TOKEN").newHandler()
# Allow the user to use `pingy` or `pin` to refer to the `ping` command 
cmd.addChatAlias("ping", ["pingy", "pin"])
  Source   Edit
proc addSlashAlias(router: CommandHandler; commandName: string;
                   aliases: openArray[string]) {....raises: [KeyError, ValueError],
    tags: [].}
Works like addChatAlias except it makes the alias for a slash command instead   Source   Edit
proc defaultHelpMessage(m: Message; handler: CommandHandler; commandName: string): owned(
    Future[void]) {....raises: [Exception],
                    tags: [ReadIOEffect, RootEffect, TimeEffect, WriteIOEffect].}
Generates the help message for all the chat commands   Source   Edit
proc getScannerCall(parameter: ProcParameter; scanner: NimNode; getInner = false): NimNode {.
    ...raises: [], tags: [].}
Construct a call but adding the needed generic types to the kind variable and then generating a call for next which takes the current scanner and the type. The corresponding next call will be looked up by Nim, this allows for easier creation of new types and also allows user created types   Source   Edit
proc handleInteraction(router: CommandHandler; s: Shard; i: Interaction): Future[
    bool] {....raises: [Exception, ValueError], tags: [RootEffect].}
Handles an incoming interaction from discord which is needed for slash commands to work. Returns true if a slash command was found and run
proc interactionCreate (s: Shard, i: Interaction) {.event(discord).} =
    discard await cmd.handleInteraction(s, i)
  Source   Edit
proc handleMessage(handler: CommandHandler; prefix: string; s: Shard;
                   msg: Message): Future[bool] {.
    ...raises: [Exception, ValueError],
    tags: [RootEffect, ReadIOEffect, TimeEffect, WriteIOEffect].}
Handles an incoming discord message and executes a command if necessary. This returns true if a command was found
proc messageCreate (s: Shard, msg: Message) {.event(discord).} =
    discard await cmd.handleMessage("$$", msg)
  Source   Edit
proc handleMessage(router: CommandHandler; prefix: string; msg: Message): Future[
    bool] {....deprecated: "Pass the shard parameter before msg",
            raises: [Exception, ValueError],
            tags: [RootEffect, ReadIOEffect, TimeEffect, WriteIOEffect].}
Deprecated: Pass the shard parameter before msg
  Source   Edit
proc handleMessage(router: CommandHandler; prefixes: seq[string]; msg: Message): Future[
    bool] {....deprecated: "Pass the shard parameter before msg",
            raises: [Exception, ValueError],
            tags: [RootEffect, ReadIOEffect, TimeEffect, WriteIOEffect].}
Deprecated: Pass the shard parameter before msg
  Source   Edit
proc handleMessage(router: CommandHandler; prefixes: seq[string]; s: Shard;
                   msg: Message): Future[bool] {.
    ...raises: [Exception, ValueError],
    tags: [RootEffect, ReadIOEffect, TimeEffect, WriteIOEffect].}
Handles an incoming discord message and executes a command if necessary. This returns true if a command was found and executed. It will return once a prefix is correctly found
proc messageCreate (s: Shard, msg: Message) {.event(discord).} =
    discard await cmd.handleMessage(["$$", "&"], msg) # Both $$ and & prefixes will be accepted
  Source   Edit
proc newHandler(discord: DiscordClient; msgVariable: string = "msg"): CommandHandler {.
    ...raises: [], tags: [].}
Creates a new handler which you can add commands to   Source   Edit
proc register(router: CommandHandler; name: string; handler: ChatCommandProc) {.
    ...raises: [KeyError, ValueError], tags: [].}
  Source   Edit
proc register(router: CommandHandler; name: string; handler: SlashCommandProc) {.
    ...raises: [KeyError, ValueError], tags: [].}
  Source   Edit
proc registerCommands(handler: CommandHandler): owned(Future[void]) {.
    ...raises: [Exception],
    tags: [RootEffect, TimeEffect, ReadIOEffect, WriteIOEffect].}
Registers all the slash commands with discord. This handles updating new command and removing old commands but it will leave old commands in a guild if you specifically add them to certain guilds and then remove those commands from your code.
proc onReady (s: Shard, r: Ready) {.event(discord).} =
    await cmd.registerCommands()

note: If you have a command group then the guildID will be choosen from the first command

  Source   Edit

Macros

macro addChat(router: CommandHandler; name: string; handler: untyped): untyped
Add a new chat command to the handler A chat command is a command that the bot handles when it gets sent a message
cmd.addChat("ping") do ():
    discord.api.sendMessage(msg.channelID, "pong")
  Source   Edit
macro addSlash(router: CommandHandler; name: string;
               parameters: varargs[untyped]): untyped
Add a new slash command to the handler A slash command is a command that the bot handles when the user uses slash commands
cmd.addSlash("hello") do ():
    ## I echo hello to the console
    echo "hello world"

# Can also be made to only run in a certain guild
cmd.addSlash("hello", guildID = "123456789") do ():
    ## I echo hello to the console
    echo "Hello world"
  Source   Edit