Lot of fixes async iterator asynchronous, plans for asynchronouse work

Mala poprawka na rozmiar plikow pamieci

Funkcjonalnosc logowania incydentow w Absinth Eldritch Horror Hammertimespace Continuum

Reakcje ladacznicy, poprawka na mention w reset the clock
This commit is contained in:
2023-06-08 14:06:25 +02:00
committed by migatu
parent d3169786ff
commit 0c9298baa4
5 changed files with 930 additions and 121 deletions
+146 -14
View File
@@ -43,6 +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/Conjurer/accident_log.json"
elif platform == "win32":
logfile = "discord.log"
@@ -53,6 +54,8 @@ elif platform == "win32":
settings_file = "settings.json"
netrc_file = "C:\\Users\\mtusz\\.netrc"
logstore = "C:\\Users\\mtusz\\OneDrive\\Pulpit\\Conjurer\\logs\\"
accident_log = "accident_log.json"
# *=========================================== Keys
netrc = netrc.netrc(netrc_file)
@@ -141,13 +144,18 @@ 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
if message.channel.id == 1084448332841230388:
return
# interrogation booth
if message.channel.id == 1111625221171052595:
return
if isinstance(message.channel, discord.DMChannel):
channel = client.get_channel(1064888712565100614)
await channel.send("Słyszałem ja żem że: " + message.content)
@@ -155,7 +163,7 @@ async def on_message(message):
channel = message.channel
await client.process_commands(message)
# 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
@@ -168,13 +176,11 @@ async def on_message(message):
if tdelta > INITIAL_TIME_WAIT:
for word in word_reactions:
if re.search(".*" + word + "[\s*,$]*", message.content):
# if word in message.content:
tdelta = datetime.now() - word_reactions[word][2]
tdelta = tdelta.total_seconds()
reaction = word_reactions[word][3]
if tdelta > word_reactions[word][1]:
# to zrobic reactiony
# TODO: to zrobic reactiony
logger.info("Ping z procedury reakcji")
if reaction:
emoji = client.get_emoji(word_reactions[word][0])
@@ -336,14 +342,65 @@ async def check():
voiceClient = client.voice_clients[0]
if voiceClient.is_connected():
global MUZYKA
while MUZYKA["playing"]:
await asyncio.sleep(10)
if not voiceClient.is_playing() and not voiceClient.is_paused():
while MUZYKA["playing"] and voiceClient.is_connected():
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....*"
)
with channel.typing():
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.
file_data = json.load(file)
new_data = []
new_data.append(file_data[0])
new_data.extend(file_data[:-20])
file.seek(0)
# convert back to json.
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....*"
)
with open(memory_five_siara, "r+") as file:
with open(path_newfile, "x") as new_file:
# First we load existing data into a dict.
file_data = json.load(file)
new_data = []
new_data.append(file_data[0])
new_data.extend(file_data[:-20])
file.seek(0)
new_file.seek(0)
# 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 asyncio.sleep(60)
@@ -522,7 +579,22 @@ async def get_file(ctx, source, link):
)
logger.error("Wrong link provided youtube: {}".format(link))
return "", None
# define an asynchronous generator
async def async_iterator_generator(range):
# normal loop
for i in range:
# yield the result
yield i
''' Alternatywna wersja przerobienia fora na asynchroniczny
# traverse the iterable of awaitables
for item in coros:
# await and get the result from the awaitable
result = await item
# report the results
print(result)
'''
async def wyszukaj(ctx, how_many=0):
# TODO: Potem dorobić wyszukiwania po kawałkach słów i sieć neuronową z możliwością wyrażenia opinii o dopasowaniu.
@@ -612,12 +684,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:
@@ -959,10 +1030,71 @@ 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, "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 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, "r+") as new_file:
# First we load existing data into a dict.
file_data = json.load(new_file)
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
await ctx.send(return_data)
@client.command()
async def reset_the_clock(ctx, arg=None):
hammer = False
for role in ctx.message.author.roles:
if role.name == "Bartender":
hammer = True
if hammer:
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")
opis = ctx.message.content[16:]
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(
"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(
"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)