Message Sending
This commit is contained in:
parent
87c1576e4f
commit
68ac5d76ee
72
commands/implemented/command_roll_discord.py
Normal file
72
commands/implemented/command_roll_discord.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
from abc import ABCMeta
|
||||||
|
|
||||||
|
from discord import message
|
||||||
|
|
||||||
|
from commands.command_base import AbstractCommand
|
||||||
|
|
||||||
|
import random
|
||||||
|
|
||||||
|
import discord
|
||||||
|
import discord.message
|
||||||
|
import discord.channel
|
||||||
|
|
||||||
|
class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
||||||
|
"""
|
||||||
|
this is the roll command.
|
||||||
|
"""
|
||||||
|
command = "!roll"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(CommandRoll.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD)
|
||||||
|
|
||||||
|
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...")
|
||||||
|
print("Rolling Dice...")
|
||||||
|
|
||||||
|
temp_preParsedMessage = discord_message.content.split("+")
|
||||||
|
|
||||||
|
tempParsedMessage = temp_preParsedMessage[0].split(" ")
|
||||||
|
temp_dice_stmt: str = tempParsedMessage[1]
|
||||||
|
parsedMessage = temp_dice_stmt.lower().split("d")
|
||||||
|
|
||||||
|
loopBool: bool = False
|
||||||
|
if parsedMessage[0] != "":
|
||||||
|
loopBool = True
|
||||||
|
if loopBool == True:
|
||||||
|
if int(parsedMessage[0]) == 1:
|
||||||
|
loopBool = False
|
||||||
|
|
||||||
|
# If roll is in xdx+x format
|
||||||
|
if loopBool == True:
|
||||||
|
rolls: list = []
|
||||||
|
for x in range(int(parsedMessage[0])):
|
||||||
|
rolls.append(random.randint(1, int(parsedMessage[1])))
|
||||||
|
|
||||||
|
rollTotal = 0
|
||||||
|
for roll in rolls:
|
||||||
|
rollTotal = rollTotal + roll
|
||||||
|
diceRoll = diceRoll + str(roll) + ", "
|
||||||
|
diceRoll = diceRoll[:-2] # This removes the last two characters in the string
|
||||||
|
|
||||||
|
if len(temp_preParsedMessage) == 2:
|
||||||
|
diceRoll = diceRoll + " + " + temp_preParsedMessage[1] + " = " + str(
|
||||||
|
rollTotal + int(temp_preParsedMessage[1]))
|
||||||
|
else:
|
||||||
|
diceRoll = diceRoll + " = " + str(rollTotal)
|
||||||
|
# If roll is in dx+x format
|
||||||
|
if loopBool == False:
|
||||||
|
roll: int = random.randint(1, int(parsedMessage[1]))
|
||||||
|
|
||||||
|
if len(temp_preParsedMessage) == 2:
|
||||||
|
diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str(
|
||||||
|
roll + int(temp_preParsedMessage[1]))
|
||||||
|
else:
|
||||||
|
diceRoll = str(roll)
|
||||||
|
|
||||||
|
diceRoll = "@" + message.author.display_name + " rolled: " + diceRoll
|
||||||
|
print(diceRoll)
|
||||||
|
discord_message.channel.send(diceRoll)
|
||||||
@ -2,6 +2,7 @@ import random
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from discord import message
|
from discord import message
|
||||||
|
from discord.client import Client
|
||||||
|
|
||||||
import config as config
|
import config as config
|
||||||
import db
|
import db
|
||||||
@ -35,6 +36,11 @@ class Discord_Module(discord.Client):
|
|||||||
#print(str(message.id))
|
#print(str(message.id))
|
||||||
#Channel ID
|
#Channel ID
|
||||||
#print(str(message.channel.id))
|
#print(str(message.channel.id))
|
||||||
|
if message.content == "//test":
|
||||||
|
await message.channel.send('test response')
|
||||||
|
|
||||||
|
def do_command(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user