Skip to content

Commit

Permalink
Add about and help
Browse files Browse the repository at this point in the history
  • Loading branch information
hannilo committed May 4, 2020
1 parent 93d2c48 commit 8b53561
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
PREFIX=!
PREFIX=!
BUILD=0.1-dev
3 changes: 2 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
load_dotenv()
TOKEN = os.getenv('TOKEN')
PREFIX = os.getenv('PREFIX')
BUILD = os.getenv('BUILD')

bot = Bot(PREFIX)
bot = Bot(commandPrefix=PREFIX, build=BUILD)
bot.run(TOKEN)
13 changes: 11 additions & 2 deletions rollbot/Bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
class Bot(discord.Client):
logger = logging.getLogger(__name__)
prefix: str
build: str
previousRoll: Dict[discord.User, DiceRoll] = {}

def __init__(self, commandPrefix='!'):
def __init__(self, commandPrefix='!', build='dev'):
super(Bot, self).__init__()
self.prefix = commandPrefix
self.build = build
self.logger.info(f"Will be reacting to '{self.prefix}'")

async def on_ready(self):
Expand Down Expand Up @@ -51,8 +53,15 @@ async def on_message(self, message: discord.Message):
if str(message.content).startswith(self.prefix + 'reroll'): # todo add command manager, enumerate
result = roller.reroll(self.previousRoll[message.author])
await message.channel.send(self.buildResultMessage(result, message))
if str(message.content).startswith(self.prefix + 'help'): # todo add command manager, enumerate
await message.channel.send(f"`{self.prefix}roll 2d4+1` - roll 2 d4 dice and add 1\n"
f"`{self.prefix}reroll` - reroll your last roll\n"
f"`{self.prefix}about` - general info")
if str(message.content).startswith(self.prefix + 'about'): # todo add command manager, enumerate
await message.channel.send(f"Build: **{self.build}**\n"
f"Source: https://github.com/hannilo/rollbot-py")

def buildResultMessage(self, roll: DiceRoll, message: discord.Message):
return f"{message.author.mention}\n" \
f"result: {roll}\n" \
f"sum ({roll.sum()} {'+' if roll.modifier >= 0 else '-'} {abs(roll.modifier)}) : {roll.sum() + roll.modifier}"
f"sum ({roll.sum()} {'+' if roll.modifier >= 0 else '-'} {abs(roll.modifier)}) : **{roll.sum() + roll.modifier}**"

0 comments on commit 8b53561

Please sign in to comment.