From 06f5112358b2fc6bbe0a1cbea476b03d00698f1e Mon Sep 17 00:00:00 2001 From: xenofem Date: Fri, 13 Nov 2020 17:13:19 -0500 Subject: [PATCH] cloned from doctor dinosaur --- .gitignore | 133 ++++++++++++++++++++++++++++++++++++++++++++ LICENSE | 19 +++++++ README.md | 19 +++++++ absolute-destiny.py | 49 ++++++++++++++++ 4 files changed, 220 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 absolute-destiny.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d4fea2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,133 @@ +token + +# ---> Python +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c42862 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +MIT License Copyright (c) 2020 xenofem + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6ad32f --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Absolute Destiny Apocalypse + +Dice roller discord bot for Powered by the Apocalypse games + +## Usage + +Message `!4` to roll 2d6+4 + +Message `!-2` to roll 2d6-2 + +## Setup + + git clone https://git.xeno.science/xenofem/absolute-destiny + cd absolute-destiny + python3 -m venv env + source env/bin/activate + pip install discord.py + echo > token + python absolute-destiny.py diff --git a/absolute-destiny.py b/absolute-destiny.py new file mode 100644 index 0000000..6f924d4 --- /dev/null +++ b/absolute-destiny.py @@ -0,0 +1,49 @@ +import discord +import random +import sys + +client = discord.Client() + +def succ(n): + if n <= 6: + return 'Miss :fire:' + elif 7 <= n and n <= 9: + return 'Partial success :person_shrugging:' + else: + return 'Total success :tada:' + +def roll(mod): + values = [] + for i in range(2): + values.append(random.randint(1,6)) + values.append(mod) + result = sum(values) + message = '{}'.format(values[0]) + for value in values[1:]: + message += '{:+}'.format(value) + message += ' = **{}**\n**{}**'.format(result, succ(result)) + + return message + +@client.event +async def on_ready(): + print('logged in as {0.user}'.format(client), file=sys.stderr) + await client.change_presence(activity=discord.Game('!n for 2d6+n')) + +@client.event +async def on_message(message): + if message.author == client.user: + return + + if message.content.startswith('!'): + try: + mod=int(message.content.split()[0][1:]) + except ValueError: + print('error parsing message {0}'.format(message.content), file=sys.stderr) + return + + await message.channel.send(roll(mod)) + +with open('token') as f: + token = f.read().strip() +client.run(token)