From a584ef534104e38224b1254dbbb96ca236f9bcca Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 24 Dec 2021 17:35:33 +0000 Subject: piss --- .gitignore | 2 ++ keith.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 .gitignore create mode 100644 keith.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..855ec1e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.py[cod] +venv/ diff --git a/keith.py b/keith.py new file mode 100644 index 0000000..546a8b8 --- /dev/null +++ b/keith.py @@ -0,0 +1,48 @@ + +import discord + +import random +import re +diceroll = re.compile(r"\b((\d+)?d(\d+))\b") +client = discord.Client() + +@client.event +async def on_ready(): + print("Logged in") + +@client.event +async def on_message(msg): + if msg.author == client.user: + return + matches = diceroll.findall(msg.content) + if matches: + resp = [] + for match in matches: + full, count, sides = match + count = 1 if count == '' else int(count) + sides = int(sides) + if sides == 0: + return + if count > 999 or sides > 9999: + resp.append("`{}`: numbers are too big for me :(".format(full)) + else: + result = 0 + rolls = [] + for i in range(count): + a = random.randint(1, sides) + result += a + if a == sides: + rolls.append("__"+str(a)+"__") + else: + rolls.append(str(a)) + resp.append( "`{}`: `{}`: **{}**".format(full, ", ".join(rolls), result) ) + + await msg.channel.send("\n".join(resp)) + +if __name__ == "__main__": + from os import getenv + tok = getenv("DICEBOT_TOKEN", None) + if tok is None: + print("Set the envvar DICEBOT_TOKEN to your token") + else: + client.run(tok.strip()) -- cgit v1.2.3