mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Aggiunti colpi critici e rimosso il casesensitive su /cast
This commit is contained in:
parent
3572056a7f
commit
bb9341d845
5 changed files with 81 additions and 47 deletions
30
bots.py
30
bots.py
|
@ -1,7 +1,9 @@
|
|||
import multiprocessing
|
||||
import os
|
||||
import telegrambot
|
||||
import discordbot
|
||||
import time
|
||||
import platform
|
||||
|
||||
discord_telegram_pipe = multiprocessing.Pipe()
|
||||
discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True)
|
||||
|
@ -10,15 +12,19 @@ telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_tel
|
|||
if __name__ == "__main__":
|
||||
discord.start()
|
||||
telegram.start()
|
||||
while True:
|
||||
if discord.exitcode is not None:
|
||||
print("Restarting Discord Bot...")
|
||||
del discord
|
||||
discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True)
|
||||
discord.start()
|
||||
if telegram.exitcode is not None:
|
||||
print("Restarting Telegram Bot...")
|
||||
del telegram
|
||||
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],), daemon=True)
|
||||
telegram.start()
|
||||
time.sleep(60)
|
||||
try:
|
||||
while True:
|
||||
if discord.exitcode is not None:
|
||||
print("Restarting Discord Bot...")
|
||||
del discord
|
||||
discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True)
|
||||
discord.start()
|
||||
if telegram.exitcode is not None:
|
||||
print("Restarting Telegram Bot...")
|
||||
del telegram
|
||||
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],), daemon=True)
|
||||
telegram.start()
|
||||
time.sleep(60)
|
||||
except KeyboardInterrupt:
|
||||
if platform.system() == "Linux":
|
||||
os.system("reset")
|
50
cast.py
Normal file
50
cast.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import random
|
||||
import math
|
||||
|
||||
|
||||
def cast(spell_name: str, target_name: str, platform: str) -> str:
|
||||
spell = spell_name.capitalize()
|
||||
# Seed the rng with the spell name
|
||||
# so that spells always deal the same damage
|
||||
random.seed(spell)
|
||||
dmg_dice = random.randrange(1, 11)
|
||||
dmg_max = random.sample([4, 6, 8, 10, 12, 20, 100], 1)[0]
|
||||
dmg_mod = random.randrange(math.floor(-dmg_max / 5), math.ceil(dmg_max / 5) + 1)
|
||||
# Reseed the rng with a random value
|
||||
# so that the dice roll always deals a different damage
|
||||
random.seed()
|
||||
total = dmg_mod
|
||||
# Check for a critical hit
|
||||
crit = 1
|
||||
while True:
|
||||
crit_die = random.randrange(1, 21)
|
||||
if crit_die == 20:
|
||||
crit *= 2
|
||||
else:
|
||||
break
|
||||
for dice in range(0, dmg_dice):
|
||||
total += random.randrange(1, dmg_max + 1)
|
||||
if crit > 1:
|
||||
if platform == "telegram":
|
||||
crit_msg = f"<b>CRITICO ×{crit}{'!' * crit}</b>\n"
|
||||
elif platform == "discord":
|
||||
crit_msg = f"**CRITICO ×{crit}{'!' * crit}**\n"
|
||||
total *= crit
|
||||
else:
|
||||
crit_msg = ""
|
||||
if platform == "telegram":
|
||||
return f"❇️ Ho lanciato <b>{spell}</b> su " \
|
||||
f"<i>{target_name}</i>.\n" \
|
||||
f"{crit_msg}" \
|
||||
f"<i>{target_name}</i> subisce {dmg_dice}d{dmg_max}" \
|
||||
f"{'+' if dmg_mod > 0 else ''}{str(dmg_mod) if dmg_mod != 0 else ''}" \
|
||||
f"{'×' + str(crit) if crit > 1 else ''}" \
|
||||
f"=<b>{total if total > 0 else 0}</b> danni!"
|
||||
elif platform == "discord":
|
||||
return f"❇️ Ho lanciato **{spell}** su " \
|
||||
f"_{target_name}_.\n" \
|
||||
f"{crit_msg}" \
|
||||
f"_{target_name}_ subisce {dmg_dice}d{dmg_max}" \
|
||||
f"{'+' if dmg_mod > 0 else ''}{str(dmg_mod) if dmg_mod != 0 else ''}" \
|
||||
f"{'×' + str(crit) if crit > 1 else ''}" \
|
||||
f"=**{total if total > 0 else 0}** danni!"
|
|
@ -6,7 +6,6 @@ import discord.voice_client
|
|||
import functools
|
||||
import sys
|
||||
import db
|
||||
import errors
|
||||
import youtube_dl
|
||||
import concurrent.futures
|
||||
import stagismo
|
||||
|
@ -18,6 +17,7 @@ import configparser
|
|||
import subprocess
|
||||
import async_timeout
|
||||
import raven
|
||||
import cast
|
||||
|
||||
# Queue emojis
|
||||
queue_emojis = [":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:", ":ten:"]
|
||||
|
@ -341,25 +341,9 @@ async def on_message(message: discord.Message):
|
|||
await client.send_message(message.channel, "⚠️ Non hai specificato nessun incantesimo!\n"
|
||||
"Sintassi corretta: `!cast <nome_incantesimo>`")
|
||||
return
|
||||
target = random.sample(list(message.server.members), 1)[0]
|
||||
# Seed the rng with the spell name
|
||||
# so that spells always deal the same damage
|
||||
random.seed(spell)
|
||||
dmg_mod = random.randrange(-2, 3)
|
||||
dmg_dice = random.randrange(1, 4)
|
||||
dmg_max = random.sample([4, 6, 8, 10, 12, 20, 100], 1)[0]
|
||||
# Reseed the rng with a random value
|
||||
# so that the dice roll always deals a different damage
|
||||
random.seed()
|
||||
total = dmg_mod
|
||||
for dice in range(0, dmg_dice):
|
||||
total += random.randrange(1, dmg_max+1)
|
||||
await client.send_message(message.channel,
|
||||
f"❇️ Ho lanciato **{spell}** "
|
||||
f"su **{target.nick if target.nick is not None else target.name}** "
|
||||
f"per {dmg_dice}d{dmg_max}"
|
||||
f"{'+' if dmg_mod > 0 else ''}{str(dmg_mod) if dmg_mod != 0 else ''}"
|
||||
f"=**{total if total > 0 else 0}** danni!")
|
||||
target: discord.Member = random.sample(list(message.server.members), 1)[0]
|
||||
await client.send_message(message.channel, cast.cast(spell_name=spell, target_name=target.name,
|
||||
platform="discord"))
|
||||
elif message.content.startswith("!smecds"):
|
||||
ds = random.sample(stagismo.listona, 1)[0]
|
||||
await client.send_message(message.channel, f"Secondo me, è colpa {ds}.", tts=True)
|
||||
|
|
|
@ -7,3 +7,4 @@ requests
|
|||
psycopg2
|
||||
PyNaCl
|
||||
async_timeout
|
||||
raven
|
|
@ -11,6 +11,7 @@ from discord import Status as DiscordStatus
|
|||
import subprocess
|
||||
import os
|
||||
import time
|
||||
import cast
|
||||
|
||||
# Init the config reader
|
||||
import configparser
|
||||
|
@ -132,7 +133,7 @@ def cmd_discord(bot: Bot, update: Update):
|
|||
|
||||
def cmd_cast(bot: Bot, update: Update):
|
||||
try:
|
||||
spell = update.message.text.split(" ", 1)[1]
|
||||
spell: str = update.message.text.split(" ", 1)[1]
|
||||
except IndexError:
|
||||
bot.send_message(update.message.chat.id, "⚠️ Non hai specificato nessun incantesimo!\n"
|
||||
"Sintassi corretta: `/cast <nome_incantesimo>`")
|
||||
|
@ -143,19 +144,10 @@ def cmd_cast(bot: Bot, update: Update):
|
|||
target = random.sample(session.query(db.Telegram).all(), 1)[0]
|
||||
# Close the session
|
||||
session.close()
|
||||
# Seed the rng with the spell name
|
||||
# so that spells always deal the same damage
|
||||
random.seed(spell)
|
||||
dmg_dice = random.randrange(1, 11)
|
||||
dmg_max = random.sample([4, 6, 8, 10, 12, 20, 100], 1)[0]
|
||||
dmg_mod = random.randrange(math.floor(-dmg_max / 5), math.ceil(dmg_max / 5) + 1)
|
||||
# Reseed the rng with a random value
|
||||
# so that the dice roll always deals a different damage
|
||||
random.seed()
|
||||
total = dmg_mod
|
||||
for dice in range(0, dmg_dice):
|
||||
total += random.randrange(1, dmg_max + 1)
|
||||
bot.send_message(update.message.chat.id, f"❇️ Ho lanciato {spell} su {target.username if target.username is not None else target.first_name} per {dmg_dice}d{dmg_max}{'+' if dmg_mod > 0 else ''}{str(dmg_mod) if dmg_mod != 0 else ''}={total if total > 0 else 0} danni!")
|
||||
bot.send_message(update.message.chat.id, cast.cast(spell_name=spell,
|
||||
target_name=target.username if target.username is not None
|
||||
else target.first_name, platform="telegram"),
|
||||
parse_mode="HTML")
|
||||
|
||||
|
||||
def cmd_color(bot: Bot, update: Update):
|
||||
|
@ -391,5 +383,6 @@ def process(arg_discord_connection):
|
|||
time.sleep(60)
|
||||
print("Telegrambot restarting...")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
process(None)
|
Loading…
Reference in a new issue