Working Discord Roll Command
This commit is contained in:
parent
7258bc0baf
commit
6c7df8674d
@ -19,12 +19,12 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
||||
def __init__(self):
|
||||
super().__init__(CommandRoll.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD)
|
||||
|
||||
def do_command(self, bot, discord_message: discord.Message):
|
||||
async def do_command(self, bot, discord_message: discord.Message):
|
||||
print("!roll Detected")
|
||||
#twitch_message.chat.send("test acknowledged")
|
||||
|
||||
diceRoll: str = ""
|
||||
discord_message.channel.send("Rolling Dice...")
|
||||
await discord_message.channel.send("Rolling Dice...")
|
||||
print("Rolling Dice...")
|
||||
|
||||
temp_preParsedMessage = discord_message.content.split("+")
|
||||
@ -67,6 +67,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
||||
else:
|
||||
diceRoll = str(roll)
|
||||
|
||||
diceRoll = "@" + message.author.display_name + " rolled: " + diceRoll
|
||||
|
||||
diceRoll = discord_message.author.mention + " rolled: " + diceRoll
|
||||
print(diceRoll)
|
||||
discord_message.channel.send(diceRoll)
|
||||
await discord_message.channel.send(diceRoll)
|
||||
@ -8,6 +8,9 @@ import config as config
|
||||
import db
|
||||
import tts
|
||||
|
||||
import commands.loader as command_loader
|
||||
from commands.command_base import AbstractCommand
|
||||
|
||||
import credentials
|
||||
|
||||
import discord
|
||||
@ -20,6 +23,8 @@ class Discord_Module(discord.Client):
|
||||
self.dbCredential: credentials.DB_Credential
|
||||
self.discordCredential: credentials.Discord_Credential
|
||||
|
||||
self.commands = command_loader.load_commands()
|
||||
|
||||
self.tts_enabled: bool = False
|
||||
|
||||
def main(self):
|
||||
@ -38,8 +43,35 @@ class Discord_Module(discord.Client):
|
||||
if message.content == "//test":
|
||||
await message.channel.send('test response')
|
||||
|
||||
await self.eval_commands(message)
|
||||
|
||||
def do_command(self):
|
||||
pass
|
||||
|
||||
async def eval_commands(self, message: discord.Message):
|
||||
# containsURL: bool = self.contains_url(message)
|
||||
try:
|
||||
#first_space_idx = message.text.index(' ')
|
||||
|
||||
# This fixes a error where if you send a command without arguments it fails because
|
||||
# it cant find the substring.
|
||||
if message.content.find(" ") != -1:
|
||||
first_space_idx = message.content.index(' ')
|
||||
else:
|
||||
first_space_idx = -1
|
||||
|
||||
command_text = ' '
|
||||
if first_space_idx > -1:
|
||||
command_text = message.content[0:first_space_idx]
|
||||
else:
|
||||
command_text = message.content
|
||||
|
||||
command = self.commands[command_text]
|
||||
if command is not None and command.command_type is AbstractCommand.CommandType.DISCORD:
|
||||
await command.do_command(self, message)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass # we don't care
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user