diff --git a/bot.py b/bot.py index 6af7e40..063ba69 100644 --- a/bot.py +++ b/bot.py @@ -43,7 +43,7 @@ if platform == "linux" or platform == "linux2": settings_file = "/home/pi/Conjurer/settings.json" netrc_file = "/home/pi/.netrc" logstore = "/home/pi/RetroPie/logs/" - accident_log = "/home/pi/accident_log.json" + accident_log = "/home/pi/Conjurer/accident_log.json" elif platform == "win32": logfile = "discord.log" @@ -144,16 +144,16 @@ async def on_message(message): if ("Conjurer Śpij Słodko Aniołku" in message.content) and vykidailo: exit() - #kanal bez bota + # kanal bez bota if message.channel.id == 1095985579147141202: return - #wentylacja + # wentylacja if message.channel.id == 1083804024173764739: return - #legendy + # legendy if message.channel.id == 1084448332841230388: return - #interrogation booth + # interrogation booth if message.channel.id == 1111625221171052595: return if isinstance(message.channel, discord.DMChannel): @@ -163,7 +163,7 @@ async def on_message(message): channel = message.channel await client.process_commands(message) - #TODO: wpiac jego reakcje we framework chatu GPT + # TODO: wpiac jego reakcje we framework chatu GPT message.content = message.content.lower() tdelta = datetime.now() - master_timeout @@ -176,12 +176,11 @@ async def on_message(message): if tdelta > INITIAL_TIME_WAIT: for word in word_reactions: if re.search(".*" + word + "[\s*,$]*", message.content): - tdelta = datetime.now() - word_reactions[word][2] tdelta = tdelta.total_seconds() reaction = word_reactions[word][3] if tdelta > word_reactions[word][1]: - #TODO: to zrobic reactiony + # TODO: to zrobic reactiony logger.info("Ping z procedury reakcji") if reaction: emoji = client.get_emoji(word_reactions[word][0]) @@ -344,19 +343,27 @@ async def check(): if voiceClient.is_connected(): global MUZYKA while MUZYKA["playing"] and voiceClient.is_connected(): - if voiceClient and not voiceClient.is_playing() and not voiceClient.is_paused(): + if ( + voiceClient + and not voiceClient.is_playing() + and not voiceClient.is_paused() + ): await play(MUZYKA["ctx"], MUZYKA["requestor"]) await asyncio.sleep(0.1) if os.path.getsize(logfile) > 600000: - shutil.copyfile(logfile,"{}discord{}.log".format(logstore, datetime.now())) + shutil.copyfile(logfile, "{}discord{}.log".format(logstore, datetime.now())) logger.info("Log rollover") handler.doRollover() if os.path.getsize(memory_five_muzyka) > 300000: channel = client.get_channel(1062047571557744721) - await channel.send("*Conjurer porządkuje bar, wypala szklanki do czysta miotaczem płomieni ze swojej zbroi i ogólnie wygląda na zajętego....*") + await channel.send( + "*Conjurer porządkuje bar, wypala szklanki do czysta miotaczem płomieni ze swojej zbroi i ogólnie wygląda na zajętego....*" + ) with channel.typing(): - path_newfile = "{}{}{}.json".format(logstore, memory_five_muzyka[:-4],datetime.now()) + path_newfile = "{}{}{}.json".format( + logstore, memory_five_muzyka[:-4], datetime.now() + ) with open(memory_five_muzyka, "r+") as file: with open(path_newfile, "x") as new_file: # First we load existing data into a dict. @@ -369,10 +376,16 @@ async def check(): new_file.seek(0) json.dump(new_data, file, indent=4) json.dump(file_data, new_file, indent=4) - await channel.send("*Przeciąga się za barem* No dobra - porobione to można dalej pi... *Zauważa spojrzenie Hammera* ...sać powieści o naszym wspaniałym barze SZEFIE!") - if os.path.getsize(memory_five_siara)> 300000: - path_newfile = "{}{}{}.json".format(logstore, memory_five_siara[:-4],datetime.now()) - await channel.send("*Conjurer porządkuje bar, ścina lekkim laserem pulsacyjnym powierzchnie baru o grubości kilku mikronów i ogólnie wygląda na zajętego....*") + await channel.send( + "*Przeciąga się za barem* No dobra - porobione to można dalej pi... *Zauważa spojrzenie Hammera* ...sać powieści o naszym wspaniałym barze SZEFIE!" + ) + if os.path.getsize(memory_five_siara) > 300000: + path_newfile = "{}{}{}.json".format( + logstore, memory_five_siara[:-4], datetime.now() + ) + await channel.send( + "*Conjurer porządkuje bar, ścina lekkim laserem pulsacyjnym powierzchnie baru o grubości kilku mikronów i ogólnie wygląda na zajętego....*" + ) with open(memory_five_siara, "r+") as file: with open(path_newfile, "x") as new_file: # First we load existing data into a dict. @@ -385,7 +398,9 @@ async def check(): # convert back to json. json.dump(new_data, file, indent=4) json.dump(file_data, new_file, indent=4) - await channel.send("*Przeciąga się za barem* No dobra - porobione to można dalej pi... *Zauważa spojrzenie Hammera* eprzyć o głupotach z klientami... Szefie... *Bierze 'ukradkowy' łyk z piersiówki*") + await channel.send( + "*Przeciąga się za barem* No dobra - porobione to można dalej pi... *Zauważa spojrzenie Hammera* eprzyć o głupotach z klientami... Szefie... *Bierze 'ukradkowy' łyk z piersiówki*" + ) await asyncio.sleep(60) @@ -654,12 +669,11 @@ async def wyszukaj(ctx, how_many=0): itr += 1 else: logger.info("Wiele plików do zagrania") - search_weight.sort(key = lambda x: x[0],reverse=True) - return_list.extend(search_weight[:int(how_many)]) + search_weight.sort(key=lambda x: x[0], reverse=True) + return_list.extend(search_weight[: int(how_many)]) return return_list - async def max_weight(list): max_weight = 0 for iter in list: @@ -1001,34 +1015,42 @@ async def przytul(ctx, arg=None): async def get_image_stable_diffusion(ctx, arg=None): pass + @client.command() async def fabryczka(ctx, arg=None): await ctx.message.reply(historia_fabryczki) + @client.command() async def chata_hammera(ctx, arg=None): - with open("accident_log.json", "r+") as new_file: + with open(accident_log, "r+") as new_file: # First we load existing data into a dict. file_data = json.load(new_file) opis = file_data[-1][0] - czas = datetime.strptime(file_data[-1][1],'%Y-%m-%d %H:%M:%S.%f') - await ctx.send("Komenda mierząca Eldritch Absinht Horror Hammertimespacecontinuum. Od ostatniego incydentu w chacie Hammera minęło {}. Incydent to: {}".format(datetime.now()-czas,opis)) -@client.command() + czas = datetime.strptime(file_data[-1][1], "%Y-%m-%d %H:%M:%S.%f") + await ctx.send( + "Komenda mierząca incydenty w Eldritch AbsinthHammerTimeSpaceContinuum.\n Od ostatniego incydentu w chacie Hammera minęło {}. Incydent to: {}".format( + datetime.now() - czas, opis + ) + ) + +@client.command() async def historia_incydentow_u_hammera(ctx, arg=None): - with open("accident_log.json", "r+") as new_file: + with open(accident_log, "r+") as new_file: # First we load existing data into a dict. file_data = json.load(new_file) - return_data = "Historia zarejestrownych incydentów u Hammera:\n" + return_data = "Komenda mierząca incydenty w Eldritch AbsinthHammerTimeSpaceContinuum.\n Historia zarejestrownych incydentów u Hammera:\n" index = 1 for data in file_data: opis = data[0] - czas = datetime.strptime(data[1],'%Y-%m-%d %H:%M:%S.%f') - add_data = "{}. Opis: {} Data: {}".format(index,opis,czas) - return_data= return_data+ add_data + "\n" - index+=1 + czas = datetime.strptime(data[1], "%Y-%m-%d %H:%M:%S.%f") + add_data = "{}. Opis: {} Data: {}".format(index, opis, czas) + return_data = return_data + add_data + "\n" + index += 1 await ctx.send(return_data) + @client.command() async def reset_the_clock(ctx, arg=None): hammer = False @@ -1036,19 +1058,28 @@ async def reset_the_clock(ctx, arg=None): if role.name == "Bartender": hammer = True if hammer: - with open("accident_log.json", "r+") as new_file: + with open(accident_log, "r+") as new_file: # First we load existing data into a dict. file_data = json.load(new_file) - czas = datetime.strptime(file_data[-1][1],'%Y-%m-%d %H:%M:%S.%f') + czas = datetime.strptime(file_data[-1][1], "%Y-%m-%d %H:%M:%S.%f") opis = ctx.message.content[16:] - accident= accident = [opis, "{}".format(datetime.now())] + accident = accident = [opis, "{}".format(datetime.now())] file_data.append(accident) new_file.seek(0) # convert back to json. json.dump(file_data, new_file, indent=4) - await ctx.send("RESET THE CLOCK. Od ostatniego incydentu w chacie Hammera minęło {}. No ale teraz odpierdolił: {}".format(czas, opis)) + await ctx.send( + "Komenda mierząca incydenty w Eldritch AbsinthHammerTimeSpaceContinuum.\n RESET THE CLOCK. Od ostatniego incydentu w chacie Hammera minęło {}. No ale teraz się odpierdoliło: {}".format( + czas, opis + ) + ) else: - await ctx.send("Gdzie z łapami do zegara? {} coś albo się komuś stało albo zaraz się stanie jak będzie zegar tykał....".format(client.get_user(346956223645614080))) + await ctx.send( + "Komenda mierząca incydenty w Eldritch AbsinthHammerTimeSpaceContinuum.\n Gdzie z łapami do zegara? {} coś albo się komuś stało albo zaraz się stanie jak będzie zegar tykał....".format( + client.get_user(346956223645614080).mention + ) + ) + # *================================== Run client.run(TOKEN)