mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +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
6
bots.py
6
bots.py
|
@ -1,7 +1,9 @@
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
import os
|
||||||
import telegrambot
|
import telegrambot
|
||||||
import discordbot
|
import discordbot
|
||||||
import time
|
import time
|
||||||
|
import platform
|
||||||
|
|
||||||
discord_telegram_pipe = multiprocessing.Pipe()
|
discord_telegram_pipe = multiprocessing.Pipe()
|
||||||
discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True)
|
discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True)
|
||||||
|
@ -10,6 +12,7 @@ telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_tel
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
discord.start()
|
discord.start()
|
||||||
telegram.start()
|
telegram.start()
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
if discord.exitcode is not None:
|
if discord.exitcode is not None:
|
||||||
print("Restarting Discord Bot...")
|
print("Restarting Discord Bot...")
|
||||||
|
@ -22,3 +25,6 @@ if __name__ == "__main__":
|
||||||
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],), daemon=True)
|
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],), daemon=True)
|
||||||
telegram.start()
|
telegram.start()
|
||||||
time.sleep(60)
|
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 functools
|
||||||
import sys
|
import sys
|
||||||
import db
|
import db
|
||||||
import errors
|
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import stagismo
|
import stagismo
|
||||||
|
@ -18,6 +17,7 @@ import configparser
|
||||||
import subprocess
|
import subprocess
|
||||||
import async_timeout
|
import async_timeout
|
||||||
import raven
|
import raven
|
||||||
|
import cast
|
||||||
|
|
||||||
# Queue emojis
|
# Queue emojis
|
||||||
queue_emojis = [":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:", ":ten:"]
|
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"
|
await client.send_message(message.channel, "⚠️ Non hai specificato nessun incantesimo!\n"
|
||||||
"Sintassi corretta: `!cast <nome_incantesimo>`")
|
"Sintassi corretta: `!cast <nome_incantesimo>`")
|
||||||
return
|
return
|
||||||
target = random.sample(list(message.server.members), 1)[0]
|
target: discord.Member = random.sample(list(message.server.members), 1)[0]
|
||||||
# Seed the rng with the spell name
|
await client.send_message(message.channel, cast.cast(spell_name=spell, target_name=target.name,
|
||||||
# so that spells always deal the same damage
|
platform="discord"))
|
||||||
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!")
|
|
||||||
elif message.content.startswith("!smecds"):
|
elif message.content.startswith("!smecds"):
|
||||||
ds = random.sample(stagismo.listona, 1)[0]
|
ds = random.sample(stagismo.listona, 1)[0]
|
||||||
await client.send_message(message.channel, f"Secondo me, è colpa {ds}.", tts=True)
|
await client.send_message(message.channel, f"Secondo me, è colpa {ds}.", tts=True)
|
||||||
|
|
|
@ -7,3 +7,4 @@ requests
|
||||||
psycopg2
|
psycopg2
|
||||||
PyNaCl
|
PyNaCl
|
||||||
async_timeout
|
async_timeout
|
||||||
|
raven
|
|
@ -11,6 +11,7 @@ from discord import Status as DiscordStatus
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import cast
|
||||||
|
|
||||||
# Init the config reader
|
# Init the config reader
|
||||||
import configparser
|
import configparser
|
||||||
|
@ -132,7 +133,7 @@ def cmd_discord(bot: Bot, update: Update):
|
||||||
|
|
||||||
def cmd_cast(bot: Bot, update: Update):
|
def cmd_cast(bot: Bot, update: Update):
|
||||||
try:
|
try:
|
||||||
spell = update.message.text.split(" ", 1)[1]
|
spell: str = update.message.text.split(" ", 1)[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
bot.send_message(update.message.chat.id, "⚠️ Non hai specificato nessun incantesimo!\n"
|
bot.send_message(update.message.chat.id, "⚠️ Non hai specificato nessun incantesimo!\n"
|
||||||
"Sintassi corretta: `/cast <nome_incantesimo>`")
|
"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]
|
target = random.sample(session.query(db.Telegram).all(), 1)[0]
|
||||||
# Close the session
|
# Close the session
|
||||||
session.close()
|
session.close()
|
||||||
# Seed the rng with the spell name
|
bot.send_message(update.message.chat.id, cast.cast(spell_name=spell,
|
||||||
# so that spells always deal the same damage
|
target_name=target.username if target.username is not None
|
||||||
random.seed(spell)
|
else target.first_name, platform="telegram"),
|
||||||
dmg_dice = random.randrange(1, 11)
|
parse_mode="HTML")
|
||||||
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!")
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_color(bot: Bot, update: Update):
|
def cmd_color(bot: Bot, update: Update):
|
||||||
|
@ -391,5 +383,6 @@ def process(arg_discord_connection):
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
print("Telegrambot restarting...")
|
print("Telegrambot restarting...")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
process(None)
|
process(None)
|
Loading…
Reference in a new issue