Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- from discord import app_commands
- from discord.app_commands import Choice
- import re
- from characterai import PyAsyncCAI
- import random
- import json
- from charAI import main
- from dados import *
- #DISCORD CONFIG
- #region
- intents = discord.Intents.all()
- bot = commands.Bot(command_prefix = '.', intents = intents)
- #endregion
- #EVENTOS
- #Bot se conectou
- #region
- @bot.event
- async def on_ready():
- with open('info.json', 'r') as file:
- info = json.load(file)
- canalId = info['canalId']
- print(f'{bot.user} se conectou')
- canalGeral = await bot.fetch_channel(canalId)
- await bot.change_presence(activity = discord.Game(name = 'D&D com outros bots'))
- await canalGeral.send('Oie, voltei')
- #endregion
- #Bot se desconectou
- #region
- @bot.event
- async def on_disconnect(ctx):
- await ctx.send('Parece que acabou a sessão, até a próxima!')
- #endregion
- #Comando errado
- #region
- #@bot.event
- # async def on_command_error(ctx, error):
- # await ctx.send(f'O comando "{ctx.message.content}" não existe {ctx.author.name}. Se precisar, digite "/help"')
- #endregion
- #GM
- #SYNC - Sincronizar bot
- #region
- @bot.command(name = 'sync')
- async def sync(ctx):
- bot.tree.copy_global_to(guild = ctx.guild)
- await bot.tree.sync(guild = ctx.guild)
- await ctx.send('sincronizada')
- #endregion
- #GMFICHA - Ver ficha de alguem
- #region
- @bot.command(name = 'gmficha')
- async def gmficha(ctx, jogador : str):
- pass
- #endregion
- #INVOKE - faz ela vir pro chat em que chamaram o comando
- #region
- @bot.command(name = 'invoke🔪')
- async def invoke(ctx, sacrifice : str = ''):
- if not sacrifice.isspace() and sacrifice != '':
- with open('info.json', 'r') as file:
- info = json.load(file)
- with open('info.json', 'w') as file:
- info['canalId'] = ctx.channel.id
- json.dump(info, file, indent = 1)
- await ctx.send(f'{sacrifice} foi um bom sacrifício, vou atender seu pedido. Agora aviso que eu to online no canal {ctx.channel.name}')
- else:
- await ctx.author.send(f'Você não fez nenhum sacrifício {ctx.author.name} 🤨')
- #endregion
- #JOGADORES
- #CRIAR - Cria um personagem
- #region
- @bot.tree.command(name = 'criar', description = 'Cria um novo personagem')
- @app_commands.describe(nome = 'Seu nome',
- idade = 'Sua idade',
- gênero = 'Quem por helicoptero de combate será morto na primeira sessão',
- força = 'Tenha capacidade física',
- reflexos = 'Reaja rapidamente ao mundo, tenha coordenação motora',
- inteligência = 'Guarde informação, entenda o mundo e pessoas',
- resistência = 'Aguente temperaturas extremas, ferimentos e envenenamento',
- atletismo = 'Use força e velocidade bruta',
- pegada = 'Segure coisas',
- nado = 'Nade em líquidos (ou gravidade zero)',
- arremesso = 'Arremesse objetos (ou pessoas)',
- percepção = 'Note seus arredores, com sentidos ou intuição',
- acrobacia = 'Use sua agilidade e equilíbrio',
- pilotagem = 'Pilote veículos ou animais',
- jogodmao = 'Manuseie objetos, roube sem ser percebido',
- furtividade = 'Passe despercebido',
- conhecimentos = 'Conheça os rumores, guarde informação',
- enganação = 'Engane os outros, seja o Bruno',
- infiltração = 'Abra cadeados, invada fortalezas',
- persuasão = 'Convença pessoas',
- sobrevivência = 'Sobreviva ao ambiente, seja selva ou concreto',
- vocações = 'suas profissões, ideais ou objetivos de vida',
- fraquezas = 'Seus defeitos e fraquezas',
- riqueza = 'Sua riqueza em geral',
- destino = 'Quantos pontos do destino você tem')
- @app_commands.choices(força = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(reflexos = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(inteligência = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(resistência = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(atletismo = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(pegada = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(nado = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(arremesso = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(percepção = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(acrobacia = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(pilotagem = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(jogodmao = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(furtividade = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(conhecimentos = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(enganação = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(infiltração = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(persuasão = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(sobrevivência = [
- app_commands.Choice(name = '-1', value = -1),
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2)
- ])
- @app_commands.choices(riqueza = [
- app_commands.Choice(name = '0', value = 0),
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2),
- app_commands.Choice(name = '3', value = 3),
- app_commands.Choice(name = '4', value = 4),
- app_commands.Choice(name = '5', value = 5),
- app_commands.Choice(name = '6', value = 6),
- app_commands.Choice(name = '7', value = 7),
- app_commands.Choice(name = '8', value = 8)
- ])
- async def criar(interaction : discord.Interaction, nome : str, idade : int, gênero : str, força : app_commands.Choice[int], reflexos : app_commands.Choice[int], inteligência : app_commands.Choice[int], resistência : app_commands.Choice[int], atletismo : app_commands.Choice[int], pegada : app_commands.Choice[int], nado : app_commands.Choice[int], arremesso : app_commands.Choice[int], percepção : app_commands.Choice[int], acrobacia : app_commands.Choice[int], pilotagem : app_commands.Choice[int], jogodmao : app_commands.Choice[int], furtividade : app_commands.Choice[int], conhecimentos : app_commands.Choice[int], enganação : app_commands.Choice[int], infiltração : app_commands.Choice[int], persuasão : app_commands.Choice[int], sobrevivência : app_commands.Choice[int], vocações : str, fraquezas : str, riqueza : app_commands.Choice[int], destino : int):
- with open('info.json', 'r') as file:
- info = json.load(file)
- if interaction.user.name not in info['jogadores']:
- info['jogadores'].append(interaction.user.name)
- info[str(interaction.user.name)] = {}
- info[str(interaction.user.name)][nome] = {
- 'nome' : nome,
- 'idade' : idade,
- 'genero' : gênero,
- 'forca' : força.value,
- 'reflexos' : reflexos.value,
- 'inteligencia' : inteligência.value,
- 'resistencia' : resistência.value,
- 'atletismo' : atletismo.value,
- 'pegada' : pegada.value,
- 'nado' : nado.value,
- 'arremesso' : arremesso.value,
- 'percepcao' : percepção.value,
- 'acrobacia' : acrobacia.value,
- 'pilotagem' : pilotagem.value,
- 'jogo de mao' : jogodmao.value,
- 'furtividade' : furtividade.value,
- 'conhecimentos' : conhecimentos.value,
- 'enganacao' : enganação.value,
- 'infiltracao' : infiltração.value,
- 'persuasao' : persuasão.value,
- 'sobrevivencia' : sobrevivência.value,
- 'vocacoes' : vocações,
- 'fraquezas' : fraquezas,
- 'riqueza' : riqueza.value,
- 'destino' : destino
- }
- with open('info.json', 'w') as file:
- json.dump(info, file, indent = 1)
- await interaction.response.send_message(f'{nome} veio ao mundo {interaction.user.mention}! 😍😍😍')
- #endregion
- #MUDAR - Altera algo sobre seu personagem
- #region
- @bot.tree.command(name = 'mudar', description = 'Muda uma propiedade do seu personagem')
- @app_commands.describe(propiedade = 'O que você quer mudar no seu personagem', valor = 'O novo valor da propiedade')
- @app_commands.choices(propiedade = [
- app_commands.Choice(name = 'nome', value = 'nome'),
- app_commands.Choice(name = 'idade', value = 'idade'),
- app_commands.Choice(name = 'gênero', value = 'genero'),
- app_commands.Choice(name = 'resistência', value = 'resistencia'),
- app_commands.Choice(name = 'atletismo', value = 'atletismo'),
- app_commands.Choice(name = 'pegada', value = 'pegada'),
- app_commands.Choice(name = 'nado', value = 'nado'),
- app_commands.Choice(name = 'arremesso', value = 'arremesso'),
- app_commands.Choice(name = 'percepção', value = 'percepcao'),
- app_commands.Choice(name = 'acrobacia', value = 'acrobacia'),
- app_commands.Choice(name = 'pilotagem', value = 'pilotagem'),
- app_commands.Choice(name = 'jogo de mão', value = 'jogo de mao'),
- app_commands.Choice(name = 'furtividade', value = 'furtividade'),
- app_commands.Choice(name = 'conhecimentos', value = 'conhecimentos'),
- app_commands.Choice(name = 'enganação', value = 'enganacao'),
- app_commands.Choice(name = 'infiltração', value = 'infiltracao'),
- app_commands.Choice(name = 'persuasão', value = 'persuasao'),
- app_commands.Choice(name = 'sobrevivência', value = 'sobrevivencia'),
- app_commands.Choice(name = 'vocações', value = 'vocacoes'),
- app_commands.Choice(name = 'riqueza', value = 'riqueza'),
- app_commands.Choice(name = 'destino', value = 'destino'),
- ])
- async def mudar(interaction : discord.Interaction, propiedade : app_commands.Choice[str], valor : str):
- with open('info.json', 'r') as file:
- info = json.load(file)
- if interaction.user.name in info['jogadores']:
- if interaction.user.display_name in info[str(interaction.user.name)]:
- with open('info.json', 'w') as file:
- if str.isdigit(valor):
- valor = int(valor)
- info[propiedade.value] = valor
- json.dump(info, file, indent = 5)
- await interaction.response.send_message(f'Partabéns {interaction.user.mention}, você alterou o seu DNA')
- else:
- await interaction.response.send_message(f'Seu nome precisa ser o mesmo do seu personagem {interaction.user.mention}')
- else:
- await interaction.response.send_message(f'Você não tem personagens {interaction.user.mention}')
- #endregion
- #ROLL - Faz um rolamento
- #region
- @bot.tree.command(name = 'roll', description = 'Role alguma habilidade')
- @app_commands.describe(habilidade = 'A habilidade que você quer rolar', nd = 'Nível de Dificuldade')
- @app_commands.choices(habilidade = [
- app_commands.Choice(name = 'resistência', value = 'resistencia'),
- app_commands.Choice(name = 'atletismo', value = 'atletismo'),
- app_commands.Choice(name = 'pegada', value = 'pegada'),
- app_commands.Choice(name = 'nado', value = 'nado'),
- app_commands.Choice(name = 'arremesso', value = 'arremesso'),
- app_commands.Choice(name = 'percepção', value = 'percepcao'),
- app_commands.Choice(name = 'acrobacia', value = 'acrobacia'),
- app_commands.Choice(name = 'pilotagem', value = 'pilotagem'),
- app_commands.Choice(name = 'jogo de mão', value = 'jogo de mao'),
- app_commands.Choice(name = 'furtividade', value = 'furtividade'),
- app_commands.Choice(name = 'conhecimentos', value = 'conhecimentos'),
- app_commands.Choice(name = 'enganação', value = 'enganacao'),
- app_commands.Choice(name = 'infiltração', value = 'infiltracao'),
- app_commands.Choice(name = 'persuasão', value = 'persuasao'),
- app_commands.Choice(name = 'sobrevivência', value = 'sobrevivencia'),
- ])
- @app_commands.choices(nd = [
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2),
- app_commands.Choice(name = '3', value = 3),
- app_commands.Choice(name = '4', value = 4),
- app_commands.Choice(name = '5', value = 5),
- app_commands.Choice(name = '6', value = 6),
- app_commands.Choice(name = '7', value = 7),
- app_commands.Choice(name = '8', value = 8)
- ])
- async def roll(interaction : discord.Interaction, habilidade : app_commands.Choice[str], nd : app_commands.Choice[int]):
- with open('info.json', 'r') as file:
- info = json.load(file)
- if interaction.user.name in info['jogadores']:
- if interaction.user.display_name in info[str(interaction.user.name)]:
- d6 = range(1, 7)
- jogador = info[interaction.user.name][interaction.user.display_name]
- vitorias = 0
- resultado = f'Nível de dificuldade: {nd.name}\n\n'
- i = 0
- if habilidade.name in forHabs:
- atr = 'forca'
- elif habilidade.name in refHabs:
- atr = 'reflexos'
- elif habilidade.name in intHabs:
- atr = 'inteligencia'
- atrVal = jogador[atr]
- habVal = jogador[habilidade.value]
- d6Result = 3 + habVal + atrVal
- while i < d6Result:
- d6Num = random.choice(d6)
- if d6Num > 3:
- vitorias += 1
- resultado += f'Dado {i + 1}: {d6Num}\n'
- i += 1
- if vitorias >= nd.value:
- resultado += f'\n{interaction.user.mention} você completou a ação, com {vitorias} vitória(s)'
- if vitorias < nd.value:
- resultado += f'\n{interaction.user.mention} você teve {vitorias} vitória(s), e não completou a ação'
- await interaction.response.send_message(resultado)
- else:
- await interaction.response.send_message(f'Seu nome precisa ser o mesmo do seu personagem {interaction.user.mention}')
- else:
- await interaction.response.send_message(f'Você não tem personagens {interaction.user.mention}')
- #endregion
- #CHANCES - Checar chances
- #region
- @bot.tree.command(name = 'chances', description = 'Verifica a chance de você conseguir fazer um rolamento')
- @app_commands.describe(dados = 'Quantos dados você tem', nd = 'Nível de dificuldade da ação')
- @app_commands.choices(dados =[
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2),
- app_commands.Choice(name = '3', value = 3),
- app_commands.Choice(name = '4', value = 4),
- app_commands.Choice(name = '5', value = 5),
- app_commands.Choice(name = '6', value = 6),
- app_commands.Choice(name = '7', value = 7),
- app_commands.Choice(name = '8', value = 8),
- app_commands.Choice(name = '9', value = 9),
- app_commands.Choice(name = '10', value = 10),
- app_commands.Choice(name = '11', value = 11),
- app_commands.Choice(name = '12', value = 12),
- app_commands.Choice(name = '13', value = 13),
- app_commands.Choice(name = '14', value = 14),
- app_commands.Choice(name = '15', value = 15),
- app_commands.Choice(name = '16', value = 16),
- app_commands.Choice(name = '17', value = 17),
- app_commands.Choice(name = '18', value = 18),
- app_commands.Choice(name = '19', value = 19),
- app_commands.Choice(name = '20', value = 20)
- ])
- @app_commands.choices(nd = [
- app_commands.Choice(name = '1', value = 1),
- app_commands.Choice(name = '2', value = 2),
- app_commands.Choice(name = '3', value = 3),
- app_commands.Choice(name = '4', value = 4),
- app_commands.Choice(name = '5', value = 5),
- app_commands.Choice(name = '6', value = 6),
- app_commands.Choice(name = '7', value = 7),
- app_commands.Choice(name = '8', value = 8)
- ])
- async def chance(interaction : discord.Interaction, dados : app_commands.Choice[int], nd : app_commands.Choice[int]):
- with open('info.json', 'r') as file:
- info = json.load(file)
- if interaction.user.name in info['jogadores']:
- if interaction.user.display_name in info[str(interaction.user.name)]:
- x = 0
- probVal = 0
- while (dados.value - x) >= nd.value:
- prob = binom(dados.value, dados.value - x) * (0.5) ** (dados.value - x) * (0.5) ** (dados.value - (dados.value - x))
- probVal += prob
- x += 1
- await interaction.response.send_message(f'{dados.name} dado(s) para um desafio nível {nd.name}.\n\nSua chance de sucesso é de {str(probVal * 100)[:4]}%')
- else:
- await interaction.response.send_message(f'Seu nome precisa ser o mesmo do seu personagem {interaction.user.mention}')
- else:
- await interaction.response.send_message(f'Você não tem personagens {interaction.user.mention}')
- #endregion
- #DADOS - Contar quantos dados tem pra uma habilidade
- #region
- @bot.tree.command(name = 'dados', description = 'Conta quantos dados você terá para rolar uma habilidade')
- @app_commands.describe(habilidade = 'Qual habilidade você quer checar?')
- @app_commands.choices(habilidade =[
- discord.app_commands.Choice(name = 'resistência', value = 'resistencia'),
- discord.app_commands.Choice(name = 'stletismo', value = 'atletismo'),
- discord.app_commands.Choice(name = 'pegada', value = 'pegada'),
- discord.app_commands.Choice(name = 'nado', value = 'nado'),
- discord.app_commands.Choice(name = 'arremesso', value = 'arremesso'),
- discord.app_commands.Choice(name = 'percepção', value = 'percepcao'),
- discord.app_commands.Choice(name = 'acrobacia', value = 'acrobacia'),
- discord.app_commands.Choice(name = 'pilotagem', value = 'pilotagem'),
- discord.app_commands.Choice(name = 'jogo de mão', value = 'jogo de mao'),
- discord.app_commands.Choice(name = 'furtividade', value = 'furtividade'),
- discord.app_commands.Choice(name = 'conhecimentos', value = 'conhecimento geral'),
- discord.app_commands.Choice(name = 'enganação', value = 'enganacao'),
- discord.app_commands.Choice(name = 'infiltração', value = 'infiltracao'),
- discord.app_commands.Choice(name = 'persuasão', value = 'persuasao'),
- discord.app_commands.Choice(name = 'sobrevivência', value = 'sobrevivencia')
- ])
- async def dados(interaction : discord.Interaction, habilidade : app_commands.Choice[str]):
- with open('info.json', 'r') as file:
- info = json.load(file)
- if interaction.user.name in info['jogadores']:
- if interaction.user.display_name in info[str(interaction.user.name)]:
- jogador = info[interaction.user.name][interaction.user.display_name]
- if habilidade.name in forHabs:
- atr = 'forca'
- elif habilidade.name in refHabs:
- atr = 'reflexos'
- elif habilidade.name in intHabs:
- atr = 'inteligencia'
- atrVal = jogador[atr]
- habVal = jogador[habilidade.value]
- d6Result = 3 + habVal + atrVal
- await interaction.response.send_message(f'Você tem {d6Result} dados base para rolar {(habilidade.name).lower()}.')
- else:
- await interaction.response.send_message(f'Seu nome precisa ser o mesmo do seu personagem {interaction.user.mention}')
- else:
- await interaction.response.send_message(f'Você não tem personagens {interaction.user.mention}')
- #endregion
- #FICHA - Ver sua ficha
- #region
- @bot.tree.command(name = 'ficha', description = 'Mostra a sua ficha')
- async def ficha(interaction : discord.Interaction):
- with open('info.json', 'r') as file:
- info = json.load(file)
- if interaction.user.name in info['jogadores']:
- if interaction.user.display_name in info[str(interaction.user.name)]:
- ficha = ''
- for index, stat in enumerate(fichaList):
- ficha += stat[0] + ': ' + str(info[interaction.user.name][interaction.user.display_name][stat[1]]) + '\n'
- if index in [2, 5, 10, 15, 20, 22]:
- ficha += '\n'
- await interaction.response.send_message(ficha)
- else:
- await interaction.response.send_message(f'Seu nome precisa ser o mesmo do seu personagem {interaction.user.mention}')
- else:
- await interaction.response.send_message(f'Você não tem personagens {interaction.user.mention}')
- #endregion
- #INTERAÇÃO
- #Mencionada
- #region
- @bot.event
- async def on_message(message):
- if bot.user.mentioned_in(message):
- with open('info.json', 'r') as file:
- info = json.load(file)
- clean_message = re.compile('@Auxi').sub('Auxi', message.clean_content)
- info['auxiPergunta'] = clean_message
- with open('info.json', 'w') as file:
- json.dump(info, file, indent = 1)
- await main()
- with open('info.json', 'r') as file:
- info = json.load(file)
- await message.channel.send(message.author.mention + info['auxiResposta'])
- await bot.process_commands(message)
- #endregion
- bot.run('MTA1ODg0NDMyOTgxODQ3MjQ1OA.GQZ7c_.sdSn_-f9EN-Adt_RtnqhbXWv5sZle1A0ayXXV4')
Advertisement
Add Comment
Please, Sign In to add comment