IT LIVES!!!
This commit is contained in:
parent
354b7a6874
commit
c61406cc59
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
||||||
|
token
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
10
README.md
10
README.md
|
@ -1,3 +1,13 @@
|
||||||
# doctor-dinosaur
|
# doctor-dinosaur
|
||||||
|
|
||||||
Dice roller discord bot for Genius: the Transgression and other World of Darkness RPGs
|
Dice roller discord bot for Genius: the Transgression and other World of Darkness RPGs
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
git clone https://git.xeno.science/xenofem/doctor-dinosaur
|
||||||
|
cd doctor-dinosaur
|
||||||
|
python3 -m venv env
|
||||||
|
source env/bin/activate
|
||||||
|
pip install discord.py
|
||||||
|
echo <token> > token
|
||||||
|
python doctor_dinosaur.py
|
71
doctor_dinosaur.py
Normal file
71
doctor_dinosaur.py
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
import discord
|
||||||
|
import random
|
||||||
|
|
||||||
|
client = discord.Client()
|
||||||
|
|
||||||
|
def succ(n):
|
||||||
|
if n == 0:
|
||||||
|
return 'Failure'
|
||||||
|
|
||||||
|
result = '{0} success{1}'.format(n, '' if n == 1 else 'es')
|
||||||
|
if n >= 5:
|
||||||
|
result += ', exceptional success! :tada:'
|
||||||
|
return result
|
||||||
|
|
||||||
|
def chance_die():
|
||||||
|
successes = 0
|
||||||
|
result = ''
|
||||||
|
roll = random.randrange(10)
|
||||||
|
if roll == 1:
|
||||||
|
return '1\n**Dramatic failure! :fire:**'
|
||||||
|
while roll == 0:
|
||||||
|
successes += 1
|
||||||
|
result += '0->'
|
||||||
|
roll = random.randrange(10)
|
||||||
|
result += '~~{0}~~'.format(roll)
|
||||||
|
return '{0}\n**{1}**'.format(result, succ(successes))
|
||||||
|
|
||||||
|
def dice(count):
|
||||||
|
results = []
|
||||||
|
successes = 0
|
||||||
|
for i in range(count):
|
||||||
|
result = ''
|
||||||
|
roll = random.randrange(10)
|
||||||
|
while roll == 0:
|
||||||
|
successes += 1
|
||||||
|
result += '0->'
|
||||||
|
roll = random.randrange(10)
|
||||||
|
if roll >= 8:
|
||||||
|
successes += 1
|
||||||
|
result += (('{0}' if roll >= 8 else '~~{0}~~').format(roll))
|
||||||
|
results.append(result)
|
||||||
|
|
||||||
|
return '{0}\n**{1}**'.format(', '.join(results), succ(successes))
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_ready():
|
||||||
|
print('logged in as {0.user}'.format(client))
|
||||||
|
await client.change_presence(activity=discord.Game('!n for n dice, !0 for chance die'))
|
||||||
|
|
||||||
|
@client.event
|
||||||
|
async def on_message(message):
|
||||||
|
if message.author == client.user:
|
||||||
|
return
|
||||||
|
|
||||||
|
if message.content.startswith('!'):
|
||||||
|
try:
|
||||||
|
count=int(message.content.split()[0][1:])
|
||||||
|
except ValueError:
|
||||||
|
print('error parsing message {0}'.format(message.content))
|
||||||
|
return
|
||||||
|
|
||||||
|
if count > 69:
|
||||||
|
await message.channel.send(':thinking:')
|
||||||
|
elif count <= 0:
|
||||||
|
await message.channel.send(chance_die())
|
||||||
|
else:
|
||||||
|
await message.channel.send(dice(count))
|
||||||
|
|
||||||
|
with open('token') as f:
|
||||||
|
token = f.read().strip()
|
||||||
|
client.run(token)
|
Loading…
Reference in a new issue