mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-18 07:42:09 +00:00
Tag: 0.2
Intermediate commits (oldest → newest): - Fixed version of spotify_dl - I also modified yt_dlp. But I do not remember what I changed. Have fun - Poprawiono obsluge rotowanych logow i troche ulepszono funkcje opowiadania o fabryczcce - Fucking windows bugfix and playlist gen fix
This commit is contained in:
@@ -26,7 +26,7 @@ from spotify_dl import youtube as youtube_download
|
||||
import yt_dlp
|
||||
from spotipy.oauth2 import SpotifyClientCredentials
|
||||
import logging.handlers as handlers
|
||||
|
||||
import shutil
|
||||
|
||||
# *=========================================== Predefines
|
||||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
@@ -42,6 +42,9 @@ if platform == "linux" or platform == "linux2":
|
||||
music_folder = "/home/pi/RetroPie/mp3/"
|
||||
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"
|
||||
memory_five_siara = "pamiec.json"
|
||||
@@ -50,6 +53,9 @@ elif platform == "win32":
|
||||
music_folder = "G:\\Muzyka\\"
|
||||
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)
|
||||
@@ -138,10 +144,18 @@ async def on_message(message):
|
||||
|
||||
if ("Conjurer Śpij Słodko Aniołku" in message.content) and vykidailo:
|
||||
exit()
|
||||
|
||||
# kanal bez bota
|
||||
if message.channel.id == 1095985579147141202:
|
||||
return
|
||||
|
||||
# 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)
|
||||
@@ -149,24 +163,24 @@ 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
|
||||
tdelta = tdelta.total_seconds()
|
||||
if "opowiedz o fabryczce" in message.content:
|
||||
await message.reply(historia_fabryczki)
|
||||
if "opowiedz mi o fabryczce" in message.content:
|
||||
await message.reply(historia_fabryczki)
|
||||
|
||||
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])
|
||||
@@ -294,7 +308,7 @@ async def play(ctx, zamawial=None, arg=None):
|
||||
|
||||
voiceClient.play(
|
||||
discord.PCMVolumeTransformer(
|
||||
discord.FFmpegPCMAudio(source=file_to_play), volume=0.15
|
||||
discord.FFmpegPCMAudio(source=file_to_play), volume=0.3
|
||||
)
|
||||
) # NIE DOTYKAC POKRĘTŁA GŁOŚNOŚCI!!!!
|
||||
if query:
|
||||
@@ -328,11 +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()))
|
||||
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)
|
||||
|
||||
|
||||
@@ -511,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.
|
||||
@@ -523,8 +606,13 @@ async def wyszukaj(ctx, how_many=0):
|
||||
search_weight.append((0, ""))
|
||||
|
||||
time_start = datetime.now()
|
||||
for word in word_list[1:]:
|
||||
if int(how_many) > 0:
|
||||
skip_start = 2
|
||||
else:
|
||||
skip_start = 1
|
||||
for word in word_list[skip_start:]:
|
||||
token_weight = len(word)
|
||||
logger.info("Słowo kluczowe: {}".format(word))
|
||||
itr = 0
|
||||
for file in music_file_list:
|
||||
if platform == "win32":
|
||||
@@ -560,7 +648,6 @@ async def wyszukaj(ctx, how_many=0):
|
||||
all_words.extend(tmp)
|
||||
pingu = 1
|
||||
pattern_len = len(all_words)
|
||||
plapka = False
|
||||
if platform == "win32":
|
||||
skip = 2
|
||||
else:
|
||||
@@ -575,10 +662,8 @@ async def wyszukaj(ctx, how_many=0):
|
||||
+ (token_weight + (pingu**1.5) / pattern_len) / matched_times
|
||||
)
|
||||
search_weight[itr] = temp_weight, music_file_list[itr]
|
||||
|
||||
matched_times += 1
|
||||
itr += 1
|
||||
await asyncio.sleep(1e-3)
|
||||
|
||||
logger.info(
|
||||
"Stworzylem tablice wag zajęło mi to {}".format(datetime.now() - time_start)
|
||||
@@ -592,30 +677,16 @@ async def wyszukaj(ctx, how_many=0):
|
||||
return_list = []
|
||||
if int(how_many) <= 0:
|
||||
logger.info("Jeden plik do zagrania")
|
||||
|
||||
while not_found:
|
||||
if search_weight[itr][0] == item_to_search:
|
||||
return_list.append(search_weight[itr][1])
|
||||
return_list.append(search_weight[itr])
|
||||
return return_list
|
||||
itr += 1
|
||||
else:
|
||||
logger.info("Wiele plików do zagrania")
|
||||
for i in range(int(how_many)):
|
||||
item_to_search = await max_weight(search_weight)
|
||||
while not_found:
|
||||
if search_weight[itr][0] == item_to_search:
|
||||
return_list.append(search_weight[itr][1])
|
||||
search_weight.remove(search_weight[itr])
|
||||
itr = 0
|
||||
logger.info("Zajęło mi to {}".format(datetime.now() - time_start))
|
||||
item_to_search = await max_weight(search_weight)
|
||||
else:
|
||||
itr += 1
|
||||
if await max_weight(search_weight) < 5:
|
||||
return return_list
|
||||
if len(return_list) >= int(how_many):
|
||||
logger.info("Zajęło mi to {}".format(datetime.now() - time_start))
|
||||
return return_list
|
||||
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):
|
||||
@@ -873,11 +944,11 @@ async def zagraj_mi_kawalek(ctx, arg=None):
|
||||
if file:
|
||||
for plik in file:
|
||||
global MUZYKA
|
||||
MUZYKA["queue"].insert(0, plik)
|
||||
MUZYKA["queue"].insert(0, plik[1])
|
||||
MUZYKA["requestor"].insert(0, ctx.author)
|
||||
metadata = eyed3.load(plik)
|
||||
metadata = eyed3.load(plik[1])
|
||||
reply = "Dodałem do playlisty {} z prywatnej kolekcji Hammera.".format(
|
||||
plik
|
||||
plik[1]
|
||||
)
|
||||
if metadata.tag.title:
|
||||
reply = "Dodałem do playlisty kawalek {}".format(metadata.tag.title)
|
||||
@@ -909,11 +980,11 @@ async def zrob_mi_plejliste(ctx, *arg):
|
||||
if file:
|
||||
for plik in file:
|
||||
global MUZYKA
|
||||
MUZYKA["queue"].insert(0, plik)
|
||||
MUZYKA["queue"].insert(0, plik[1])
|
||||
MUZYKA["requestor"].insert(0, ctx.author)
|
||||
metadata = eyed3.load(plik)
|
||||
metadata = eyed3.load(plik[1])
|
||||
reply = "Dodałem do playlisty {} z prywatnej kolekcji Hammera.".format(
|
||||
plik
|
||||
plik[1]
|
||||
)
|
||||
if metadata.tag.title:
|
||||
reply = "Dodałem do playlisty kawalek {}".format(metadata.tag.title)
|
||||
@@ -960,5 +1031,70 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user