async def ping(ctx, msg, client): ping_embed = discord.Embed(title=f'⌛️ {round(client.latency * 1000)} ms', color=0x22a7f0) await ctx.channel.send(embed=ping_embed) mysql_command( f"update status_api set disc = {client.latency * 1000} where id = 1")
async def setadm(ctx, msg, client): role = msg[0] if ctx.author.id == ctx.guild.owner.id: try: role = int(role) role_obj = ctx.guild.get_role(role) assert role_obj != None except Exception: try: role = role[3:-1] role = int(role) role_obj = ctx.guild.get_role(role) assert role_obj != None except Exception: await ctx.channel.send(embed = setadm_erro()) return try: data = mysql_command(f'select * from adm_roles where server = {ctx.guild.id}', True)[0] mysql_command(f'update adm_roles set id_role = {role} where server = {ctx.guild.id}') except Exception: mysql_command(f'insert into adm_roles (server, id_role) value ({ctx.guild.id}, {role})') await ctx.channel.send(embed = setadm_alterado(role_obj)) else: await ctx.channel.send(embed = setadm_neg(ctx.guild.owner))
async def remover(ctx, msg, client): nome = msg[0].lower().capitalize() data = mysql_command(f"select * from pnts where nome = '{nome}' and server = {ctx.guild.id}", True) if len(data) != 0: mysql_command(f"delete from pnts where id_pontos = {data[0]['id_pontos']} and server = {ctx.guild.id}") await ctx.channel.send(embed = remover_nome(nome)) return await ctx.channel.send(embed = erro(nome))
async def novo(ctx, msg, client): nome = msg[0].lower().capitalize() data = mysql_command( f'select nome from pnts where nome = "{nome}" and server = {ctx.guild.id}', True) if len(data) != 0: await ctx.channel.send(embed=novo_repetido(nome)) else: mysql_command( f'insert into pnts (nome, server) value ("{nome}", {ctx.guild.id})' ) await ctx.channel.send(embed=novo_adicionado(nome))
def api_request(qnt, dado): reqData = { "jsonrpc": "2.0", "method": "generateIntegers", "params": { "apiKey": "00000000-0000-0000-0000-000000000000", "n": 10, "min": 1, "max": 10, "replacement": True, "base": 10 }, "id": 13058 } with open('./bot/settings/settings.yaml', 'r') as f: reqKey = yaml.load(f, Loader=yaml.FullLoader) reqData['params']['apiKey'] = reqKey['RNG_KEY'] reqData['id'] = reqKey['RNG_ID'] reqData['params']['n'] = str(qnt) reqData['params']['max'] = str(dado) start = time.time() response = requests.post('https://api.random.org/json-rpc/2/invoke', json=reqData) response.raise_for_status() json = response.json() done = time.time() delay = (done - start) * 1000 mysql_command("update status_api set rand = %d where id = 1" % delay) data = json['result']['random']['data'] # O Bot limita as requests quando atinge esses valores # Para desativar essa função é só apagar essas linhas do if abaixo ou o comando que escreve no arquivo settings.yaml if json['result']['bitsLeft'] <= 100 or json['result'][ 'requestsLeft'] <= 10: reqKey['RNG_KEY'] = None with open('./bot/settings/settings.yaml', 'w') as f: yaml.dump(reqKey, f) mysql_command(f"update status_api set rand = 0 where id = 1") return data
def verificaMute(cls, guild, user): mute = mysql_command( f"select * from mute where user = {user} and server = {guild}", True) if len(mute) != 0: mute = mute[0] if mute['expires'] == None: return None if mute['expires'] < datetime.today(): mysql_command(f"delete from mute where id = {mute['id']}") return False else: return mute['expires'] else: return False
async def pontos(ctx, msg, client): data = mysql_command( f"select nome, pontos from pnts where server = {ctx.guild.id} order by pontos desc", True) if len(data) == 0: await ctx.channel.send(embed=pontos_vazio()) else: await ctx.channel.send(embed=pontos_lista(data))
def verificaAviso(cls, guild, user): data = list( mysql_command( f"select * from aviso where server = {guild} and user = {user}", True)) removed = False for aviso in data: if aviso['expires'] < datetime.today(): mysql_command(f"delete from aviso where id = {aviso['id']}") removed = True if removed: data = list( mysql_command( f"select * from aviso where server = {guild} and user = {user}", True)) return len(data)
def status(): try: db = True data = mysql_command('select rand, disc from status_api where id = 1', True) except Exception: db = False return render_template('status.html', random=data[0]['rand'], discord=data[0]['disc'], db=db, BotName=BotName)
async def reset(ctx, msg, client): pnts = mysql_command("select * from pnts", True) try: role_perm = mysql_command( f"select * from adm_roles where server = {ctx.guild.id}", True)[0]['id_role'] except Exception: await ctx.channel.send(embed=reset_none()) return if len(pnts) != 0: for role in ctx.author.roles: if role_perm == role.id: mysql_command( f"delete from pnts where server = {ctx.guild.id}") await ctx.channel.send(embed=reset_true()) return await ctx.channel.send(embed=reset_false()) else: await ctx.channel.send(embed=reset_fail())
def adicionaAvisoMute(cls, guild, user, tempo, table): if tempo == 0: mysql_command( f"insert into {table} (server, user, expires) value ({guild}, {user}, 0)" ) return intervalo = 0 if tempo // 3600: tempo //= 3600 intervalo = 'hour' elif tempo // 60 and not intervalo: tempo //= 60 intervalo = 'minute' elif not intervalo: intervalo = 'second' mysql_command( f"insert into {table} (server, user, expires) value ({guild}, {user}, now() + interval {tempo} {intervalo})" )
async def add(ctx, msg, client): with open('./bot/settings/settings.yaml', 'r') as f: settings = yaml.load(f, Loader= yaml.FullLoader) nome = msg[1].lower().capitalize() try: ponto = int(msg[0]) assert int(ponto) > 0 if int(ponto) > settings['LIM_ADD']: await ctx.channel.send(embed = add_limite()) return except Exception: await ctx.channel.send(embed = add_erro()) return try: data = mysql_command(f"select * from pnts where nome = '{nome}' and server = {ctx.guild.id}", True)[0] except Exception: await ctx.channel.send(embed = erro(nome)) return data = mysql_command(f"select * from pnts where nome = '{nome}' and server = {ctx.guild.id}", True) finalponto = int(data[0]['pontos']) + int(ponto) mysql_command(f"update pnts set pontos = {finalponto} where id_pontos = {data[0]['id_pontos']} and server = {ctx.guild.id}") if int(ponto) == 1: await ctx.channel.send(embed = add_singular(nome)) return else: await ctx.channel.send(embed = add_plural(nome, ponto)) return await ctx.channel.send(embed = add_erro())
async def retirar(ctx, msg, client): try: ponto = int(msg[0]) assert int(ponto) > 0 except Exception: await ctx.channel.send(embed=retirar_erro()) return nome = msg[1].lower().capitalize() data = mysql_command( f"select * from pnts where nome = '{nome}' and server = {ctx.guild.id}", True) if len(data) != 0: if int(data[0]['pontos']) - int(ponto) >= 0: finalponto = int(data[0]['pontos']) - int(ponto) mysql_command( f"update pnts set pontos = {finalponto} where id_pontos = {data[0]['id_pontos']} and server = {ctx.guild.id}" ) if int(ponto) == 1: await ctx.channel.send(embed=retirar_singular(nome)) return else: await ctx.channel.send(embed=retirar_plural()) return else: await ctx.channel.send(embed=retirar_erro()) return await ctx.channel.send(embed=erro(nome))
async def filter(cls, ctx, client): # Verifica se a mensagem não é de BOT if ctx.author.bot: return # Verifica se está mutado mute = cls.verificaMute(ctx.guild.id, ctx.author.id) if mute: await ctx.delete() await ctx.author.send(embed=tempo_mute(ctx.guild.name, mute)) return elif mute == None: await ctx.delete() await ctx.author.send(embed=mute_perma(ctx.guild.name)) return data = cls.getData(ctx) # Verifica se é um comando com o prefixo certo if ctx.content.lower().startswith(f'{data["prefix"]}'): msg = ctx.content.split(' ') comando = msg[0].split(f'{data["prefix"]}') # Comando no chat proibido for chats in data['chatsDisable']: if chats == str(ctx.channel.id): if data['chatsDisableMsg']: await ctx.delete() await ctx.author.send(embed=comandos_error_dm( ctx.channel.name, ctx.guild.name)) return else: await ctx.channel.send(embed=comandos_error_channel()) return # Comando proibido for comands in data['comandos']: if comands == comando[1]: return await manager(ctx, comando[1], msg, client) else: # Verifica se não é adm try: adm_roles = mysql_command( f"select id_role from adm_roles where server = {ctx.guild.id}", True)[0]['id_role'] except Exception: adm_roles = 0 for role in ctx.author.roles: if role.id == adm_roles: return # Auto Moderation penalidade = False # Ban Words if data['banWords']: banWord = banWords(ctx, data['banWordsList']) if banWord: penalidade = True if data['localMsgAviso']: msgBanWord = await ctx.author.send(embed=embed_banWord( banWord, ctx.author.name, ctx.guild.name)) else: msgBanWord = await ctx.channel.send( embed=embed_banWord(banWord, ctx.author.name, ctx.guild.name)) cls.adicionaAvisoMute(ctx.guild.id, ctx.author.id, data['tempoAviso'], 'aviso') # Flood if data['flood']: floodword = flood(ctx) if floodword: penalidade = True if data['localMsgAviso']: msgFlood = await ctx.author.send(embed=embed_flood( floodword, ctx.author.name, ctx.guild.name)) else: msgFlood = await ctx.channel.send(embed=embed_flood( floodword, ctx.author.name, ctx.guild.name)) cls.adicionaAvisoMute(ctx.guild.id, ctx.author.id, data['tempoAviso'], 'aviso') # Link proibido if data['link']: urls = link(ctx, data['linkList']) if urls: penalidade = True if data['localMsgAviso']: msgLink = await ctx.author.send(embed=embed_link( urls, ctx.author.name, ctx.guild.name)) else: msgLink = await ctx.channel.send(embed=embed_link( urls, ctx.author.name, ctx.guild.name)) cls.adicionaAvisoMute(ctx.guild.id, ctx.author.id, data['tempoAviso'], 'aviso') # Spam de CAPS if data['spamcaps']: spam = spamcaps(ctx) if spam: penalidade = True if data['localMsgAviso']: msgSpam = await ctx.author.send(embed=embed_spamcaps( ctx.author.name, ctx.guild.name)) else: msgSpam = await ctx.channel.send(embed=embed_spamcaps( ctx.author.name, ctx.guild.name)) cls.adicionaAvisoMute(ctx.guild.id, ctx.author.id, data['tempoAviso'], 'aviso') # Verifica se a mensagem vai ser deletada if penalidade: await ctx.delete() numAvisos = cls.verificaAviso(ctx.guild.id, ctx.author.id) # Verifica penalidades if numAvisos != 0 and penalidade: # BAN if numAvisos >= data['numBan'] and data['numBan']: await ctx.author.send( embed=dm_ban(ctx.guild.name, data['numBan'])) await ctx.guild.ban( ctx.author, reason=f'Ban: Atingiu um total de {data["numBan"]} avisos', delete_message_days=7) # SOFTBAN if numAvisos >= data['numSoftBan'] and data['numSoftBan']: await ctx.author.send( embed=dm_softban(ctx.guild.name, data['numSoftBan'])) await ctx.guild.ban( ctx.author, reason= f'SoftBan: Atingiu um total de {data["numSoftBan"]} avisos', delete_message_days=7) await ctx.guild.unban( ctx.author, reason= f'SoftBan: Atingiu um total de {data["numSoftBan"]} avisos' ) # KICK if numAvisos >= data['numKick'] and data['numKick']: await ctx.author.send( embed=dm_kick(ctx.guild.name, data['numKick'])) await ctx.guild.kick( ctx.author, reason=f'Atingiu um total de {data["numKick"]} avisos') # MUTE if numAvisos >= data['numMute'] and data['numMute']: cls.adicionaAvisoMute(ctx.guild.id, ctx.author.id, data['tempoMute'], 'mute') await ctx.author.send( embed=embed_mute(ctx.guild.name, data['tempoMute'])) # Adiciona o numero de avisos na mensagem da penalidade with suppress(Exception): await msgBanWord.edit(embed=embed_banWord( banWord, ctx.author.name, ctx.guild.name, numAvisos)) with suppress(Exception): await msgFlood.edit(embed=embed_flood(floodword, ctx.author.name, ctx.guild.name, numAvisos)) with suppress(Exception): await msgLink.edit(embed=embed_link(urls, ctx.author.name, ctx.guild.name, numAvisos)) with suppress(Exception): await msgSpam.edit(embed=embed_spamcaps(ctx.author.name, ctx.guild.name, numAvisos))