Added dice rolling command.
parent
283e825afe
commit
33addf5b5f
|
@ -22,3 +22,4 @@
|
||||||
**!conch** or **!magicconch**: Same as the 8ball command but waaaaay cooler
|
**!conch** or **!magicconch**: Same as the 8ball command but waaaaay cooler
|
||||||
**!giveaway prize**: Do a giveaway based on users reacting with the emoji you react with secretly. Use in private and replace prize with an actual prize!
|
**!giveaway prize**: Do a giveaway based on users reacting with the emoji you react with secretly. Use in private and replace prize with an actual prize!
|
||||||
**!np**: Posts currently playing info for ToukuFM
|
**!np**: Posts currently playing info for ToukuFM
|
||||||
|
**!roll**: Rolls any number of dice! Use like `!roll d20`, `!roll 2d6`, or `!roll 3d6 d20`
|
53
pocketbot.py
53
pocketbot.py
|
@ -9,6 +9,7 @@ import praw
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
#Get script location
|
#Get script location
|
||||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
@ -32,6 +33,12 @@ reddit = praw.Reddit(client_id=reddit_client_id,client_secret=reddit_client_secr
|
||||||
metadataurl = config.get("configuration", "metadataurl")
|
metadataurl = config.get("configuration", "metadataurl")
|
||||||
iceurl = config.get("configuration", "iceurl")
|
iceurl = config.get("configuration", "iceurl")
|
||||||
|
|
||||||
|
#Dice Rolling Function
|
||||||
|
def rolldie(x):
|
||||||
|
sides = int(x[1:])
|
||||||
|
roll = random.randint(1,sides)
|
||||||
|
return roll
|
||||||
|
|
||||||
client = discord.Client()
|
client = discord.Client()
|
||||||
|
|
||||||
#Subroutine to get UPS Status
|
#Subroutine to get UPS Status
|
||||||
|
@ -265,6 +272,52 @@ def on_message(message):
|
||||||
mixes = json.loads(requests.get("https://maki.jawa.moe/mixesjson/").text)
|
mixes = json.loads(requests.get("https://maki.jawa.moe/mixesjson/").text)
|
||||||
yield from client.send_message(message.channel, "https://maki.jawa.moe/mixes/" + random.choice(mixes)['name'])
|
yield from client.send_message(message.channel, "https://maki.jawa.moe/mixes/" + random.choice(mixes)['name'])
|
||||||
|
|
||||||
|
#Dice Roller (support rolling multiple dice at once)
|
||||||
|
elif message.content.lower().startswith('!roll'):
|
||||||
|
#Set starting Variables
|
||||||
|
args = message.content.partition(' ')[2].upper()
|
||||||
|
argsplit = args.split()
|
||||||
|
output = message.author.display_name + " rolled "
|
||||||
|
rolltotal = 0
|
||||||
|
|
||||||
|
#Go through each requested roll
|
||||||
|
for arg in argsplit:
|
||||||
|
#Roll once die multiple times (eg 20d20)
|
||||||
|
if re.match('^[0-9]+D[0-9]+$', arg):
|
||||||
|
dlocation = arg.index('D')
|
||||||
|
rolls = int(arg[:dlocation])
|
||||||
|
arg = arg[dlocation:]
|
||||||
|
if rolls <= 25:
|
||||||
|
while rolls > 0:
|
||||||
|
rollresult = rolldie(arg)
|
||||||
|
output = output + arg + ": **" + str(rollresult) + "**, "
|
||||||
|
rolltotal += rollresult
|
||||||
|
rolls -= 1
|
||||||
|
else:
|
||||||
|
rollminitotal = 0
|
||||||
|
output = output + str(rolls) + '\*' + arg + ": **"
|
||||||
|
while rolls > 0:
|
||||||
|
rollresult = rolldie(arg)
|
||||||
|
rollminitotal += rollresult
|
||||||
|
rolls -= 1
|
||||||
|
output = output + str(rollminitotal) + "**, "
|
||||||
|
rolltotal += rollminitotal
|
||||||
|
#Roll a single die (eg d20)
|
||||||
|
elif re.match('^D[0-9]+$', arg):
|
||||||
|
rollresult = rolldie(arg)
|
||||||
|
output = output + arg + ": **" + str(rollresult) + "**, "
|
||||||
|
rolltotal += rollresult
|
||||||
|
|
||||||
|
#Finish generating message
|
||||||
|
if rolltotal > 0:
|
||||||
|
output = output + "for a total of **" + str(rolltotal) + "**!"
|
||||||
|
#Print error if no dice were rolled (aka if the total is still zero)
|
||||||
|
else:
|
||||||
|
output = "Oops, looks like no dice were rolled! Try something like `!roll d20`, `!roll 2d6`, or `!roll 3d6 d20` instead."
|
||||||
|
|
||||||
|
#Send output to chat
|
||||||
|
yield from client.send_message(message.channel, output)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
client.loop.create_task(ups_check())
|
client.loop.create_task(ups_check())
|
||||||
|
|
Loading…
Reference in New Issue