Compare commits

...

34 Commits

Author SHA1 Message Date
gitea cfb26d95a4 Nowy lepszy trunk 2024-04-10 15:25:53 +02:00
gitea 5e14299fef Additional lines of code 2024-04-10 15:25:40 +02:00
gitea 126de9a4a4 Fix 2024-04-10 15:16:22 +02:00
gitea 0d132983fc Fix 2.0 2024-04-10 15:05:43 +02:00
gitea 67cae0e68e Fix 2024-04-10 15:05:43 +02:00
gitea eabd0e8e1e Nope 2024-04-10 15:05:43 +02:00
gitea f7c91e3874 Test chat gpt4 2024-04-10 15:05:43 +02:00
gitea c224b2ccc8 Hejo 2024-04-10 15:05:43 +02:00
gitea 3ca9f2c6f3 -1 2024-04-10 15:04:41 +02:00
gitea c52d55e0a2 +1 2024-04-10 15:04:41 +02:00
gitea e1fa15abb3 Async 2024-04-10 15:04:41 +02:00
gitea 74c76e639d Async fix 2024-04-10 15:04:41 +02:00
gitea 35a65e48e9 And even more async 2024-04-10 15:04:41 +02:00
gitea 5d5c136b41 More async 2024-04-10 15:04:40 +02:00
gitea b9fbc0f910 Async wyszukaj 2024-04-10 15:04:40 +02:00
gitea fd742c8f1c Parametryzacja "muzyki mojego ludu" 2024-04-10 15:04:40 +02:00
gitea 1c240342c5 Logging 2024-04-10 15:04:37 +02:00
gitea 7bd0c0aca4 Fix 2.6 2024-04-10 15:04:37 +02:00
gitea 7c8ad99743 Fix 2 2024-04-10 15:04:37 +02:00
gitea 90896fa9be Fix 1 2024-04-10 15:04:37 +02:00
gitea e3bec6bc11 Playlist based on chat history 2024-04-10 15:04:37 +02:00
gitea aa00045dec Trunk + mod 2024-04-10 15:04:32 +02:00
gitea 06e3671ec2 Linting is done 2024-04-10 15:04:22 +02:00
gitea 0879796cc6 Linting 2024-04-10 15:04:13 +02:00
gitea 9f756b3092 Dodana procedura asynchronicznej generacji iteratora oraz komentarz w
jaki sposob inaczej przerobic fora na asynchroniczny. Przydatne ze
wzgledu na to ze szukajka nadal blokuje heartbeat bota - co skutkuje
warningnami i wyjatkami
2024-04-10 15:04:09 +02:00
gitea 579a3f2a52 Reakcje ladacznicy, poprawka na mention w reset the clock 2024-04-10 15:04:09 +02:00
gitea 5505022dbb Funkcjonalnosc logowania incydentow w Absinth Eldritch Horror
Hammertimespace Continuum
2024-04-10 15:04:05 +02:00
gitea d2e5a34b87 Mala poprawka na rozmiar plikow pamieci 2024-04-10 15:03:55 +02:00
gitea c7696fafdc Fixed playlist gen 2024-04-10 15:03:43 +02:00
gitea 7f3de2ea13 Kurwa bugfix pod windowsa 2024-04-10 15:03:42 +02:00
gitea ec505f050f modified 2024-04-10 14:22:01 +02:00
gitea f55c4ce1a7 Nowy lepszy trunk
Additional lines of code

1

AAA
2024-04-10 14:22:00 +02:00
gitea 432abc73b9 Upgrade gpt model 2024-04-10 14:22:00 +02:00
gitea cdaf2589b3 Library update
fix

1111

tezz
2024-04-10 14:22:00 +02:00
13 changed files with 1952 additions and 161 deletions
+5
View File
@@ -6,3 +6,8 @@
plugins plugins
user_trunk.yaml user_trunk.yaml
user.yaml user.yaml
<<<<<<< HEAD
tmp
=======
tools
>>>>>>> c7dc465 (Parametryzacja "muzyki mojego ludu")
+2
View File
@@ -0,0 +1,2 @@
[settings]
profile=black
-3
View File
@@ -2,9 +2,6 @@ rules:
quoted-strings: quoted-strings:
required: only-when-needed required: only-when-needed
extra-allowed: ["{|}"] extra-allowed: ["{|}"]
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
key-duplicates: {} key-duplicates: {}
octal-values: octal-values:
forbid-implicit-octal: true forbid-implicit-octal: true
+5
View File
@@ -0,0 +1,5 @@
# Generic, formatter-friendly config.
select = ["B", "D3", "E", "F"]
# Never enforce `E501` (line length violations). This should be handled by formatters.
ignore = ["E501"]
+37 -7
View File
@@ -1,19 +1,29 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1 version: 0.1
cli: cli:
version: 1.14.2 <<<<<<< HEAD
version: 1.20.1
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins: plugins:
sources: sources:
- id: trunk - id: trunk
ref: v1.2.1 ref: v1.4.5
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
=======
version: 1.12.1
plugins:
sources:
- id: trunk
ref: v0.0.22
uri: https://github.com/trunk-io/plugins uri: https://github.com/trunk-io/plugins
lint: lint:
enabled: enabled:
- checkov@2.4.9
- yamllint@1.32.0
- actionlint@1.6.25 - actionlint@1.6.25
- markdownlint@0.35.0 - markdownlint@0.35.0
- trivy@0.44.1 - trivy@0.43.1
- trufflehog@3.54.0 - trufflehog@3.44.0
- pylint - pylint
- codespell - codespell
- cspell - cspell
@@ -33,11 +43,31 @@ lint:
- yapf - yapf
- gitleaks - gitleaks
>>>>>>> c7dc465 (Parametryzacja "muzyki mojego ludu")
runtimes: runtimes:
enabled: enabled:
- go@1.19.5
- node@18.12.1 - node@18.12.1
- python@3.10.8 - python@3.10.8
<<<<<<< HEAD
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
lint:
enabled:
- actionlint@1.6.27
- bandit@1.7.8
- black@24.3.0
- codespell
- checkov@3.2.48
- git-diff-check
- isort@5.13.2
- pylint
- markdownlint@0.39.0
- prettier@3.2.5
- ruff@0.3.4
- trivy@0.50.1
- trufflehog@3.71.0
- yamllint@1.35.1
=======
>>>>>>> c7dc465 (Parametryzacja "muzyki mojego ludu")
actions: actions:
disabled: disabled:
- trunk-announce - trunk-announce
-2
View File
@@ -1,6 +1,4 @@
{ {
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"trunk.inlineDecorators": true, "trunk.inlineDecorators": true,
"trunk.inlineDecoratorsForAllExtensions": true, "trunk.inlineDecoratorsForAllExtensions": true,
"trunk.showPreexistingIssues": true, "trunk.showPreexistingIssues": true,
+43 -148
View File
@@ -35,12 +35,11 @@ import pdf2image
import PyPDF2 import PyPDF2
import requests import requests
import spotipy import spotipy
import tiktoken
from discord.ext import commands from discord.ext import commands
from spotipy.oauth2 import SpotifyClientCredentials from spotipy.oauth2 import SpotifyClientCredentials
import yt_dlp
from spotify_dl import youtube as youtube_download from spotify_dl import youtube as youtube_download
from spotify_dl import spotify from spotify_dl import spotify
Music_Config = TypedDict( Music_Config = TypedDict(
@@ -70,9 +69,10 @@ SETTINGS_FILE = ""
ENCODING = "" ENCODING = ""
GRAPHICS_PATH = "" GRAPHICS_PATH = ""
MUZYKA_MOJEGO_LUDU_HISTORIA = 1500 MUZYKA_MOJEGO_LUDU_HISTORIA = 1500
MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = 15 MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = 30
MUZYKA_MOJEGO_LUDU_PLAJLISTA = 30 MUZYKA_MOJEGO_LUDU_PLAJLISTA = 30
# *=========================================== Platform Specific Predefines # *=========================================== Platform Specific Predefines
if platform in ("linux", "linux2"): if platform in ("linux", "linux2"):
@@ -80,7 +80,6 @@ if platform in ("linux", "linux2"):
if "microsoft-standard" in uname().release: if "microsoft-standard" in uname().release:
LOGFILE = "/home/mtuszowski/conjurer/discord.log" LOGFILE = "/home/mtuszowski/conjurer/discord.log"
MEMORY_FIVE_SIARA = "/home/mtuszowski/conjurer/pamiec.json" MEMORY_FIVE_SIARA = "/home/mtuszowski/conjurer/pamiec.json"
SYSTEM_GPT_SETTINGS = "/home/mtuszowski/conjurer/system_gpt_settings.json"
MEMORY_FIVE_MUZYKA = "/home/mtuszowski/conjurer/pamiec_muzyki.json" MEMORY_FIVE_MUZYKA = "/home/mtuszowski/conjurer/pamiec_muzyki.json"
MUSIC_FOLDER = "/mnt/g/Muzyka/" MUSIC_FOLDER = "/mnt/g/Muzyka/"
SETTINGS_FILE = "/home/mtuszowski/conjurer/settings.json" SETTINGS_FILE = "/home/mtuszowski/conjurer/settings.json"
@@ -94,7 +93,6 @@ if platform in ("linux", "linux2"):
else: else:
LOGFILE = "/home/pi/Conjurer/discord.log" LOGFILE = "/home/pi/Conjurer/discord.log"
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json" MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json"
SYSTEM_GPT_SETTINGS = "/home/pi/Conjurer/system_gpt_settings.json"
MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json" MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json"
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/" MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
SETTINGS_FILE = "/home/pi/Conjurer/settings.json" SETTINGS_FILE = "/home/pi/Conjurer/settings.json"
@@ -109,7 +107,6 @@ if platform in ("linux", "linux2"):
elif platform == "win32": elif platform == "win32":
LOGFILE = "discord.log" LOGFILE = "discord.log"
MEMORY_FIVE_SIARA = "pamiec.json" MEMORY_FIVE_SIARA = "pamiec.json"
SYSTEM_GPT_SETTINGS = "system_gpt_settings.json"
MEMORY_FIVE_MUZYKA = "pamiec_muzyki.json" MEMORY_FIVE_MUZYKA = "pamiec_muzyki.json"
MUSIC_FOLDER = "G:\\Muzyka\\" MUSIC_FOLDER = "G:\\Muzyka\\"
SETTINGS_FILE = "settings.json" SETTINGS_FILE = "settings.json"
@@ -170,10 +167,6 @@ for mp3_item in Path.glob(Path(MUSIC_FOLDER), "**/*.mp3"):
if platform == "win32": if platform == "win32":
temp_music_file = temp_music_file.replace("/", "\\") temp_music_file = temp_music_file.replace("/", "\\")
music_file_list.append(temp_music_file) music_file_list.append(temp_music_file)
with open(SYSTEM_GPT_SETTINGS, "r+", encoding=ENCODING) as temp_settings_file:
# First we load existing data into a dict.
GPT_SETTINGS = json.load(temp_settings_file)
with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as temp_memory_file: with open(MEMORY_FIVE_SIARA, "r+", encoding=ENCODING) as temp_memory_file:
# First we load existing data into a dict. # First we load existing data into a dict.
MESSAGE_TABLE = json.load(temp_memory_file) MESSAGE_TABLE = json.load(temp_memory_file)
@@ -183,7 +176,6 @@ with open(MEMORY_FIVE_MUZYKA, "r+", encoding=ENCODING) as temp_music_memory_file
with open(SETTINGS_FILE, "r", encoding=ENCODING) as f_settings_file: with open(SETTINGS_FILE, "r", encoding=ENCODING) as f_settings_file:
data = json.load(f_settings_file) data = json.load(f_settings_file)
word_reactions = data["word_reactions"] word_reactions = data["word_reactions"]
cyclic_words = data["cyclic_words"]
historia_fabryczki = data["fabryczka"] historia_fabryczki = data["fabryczka"]
for key in word_reactions: for key in word_reactions:
word_reactions[key][2] = datetime.now() word_reactions[key][2] = datetime.now()
@@ -278,12 +270,8 @@ async def on_message(message):
word_reactions[word][2] = datetime.now() word_reactions[word][2] = datetime.now()
# TODO: drobne literówki, mentiony, spacja przed dwukropkiem. napraw. # TODO: drobne literówki, mentiony, spacja przed dwukropkiem. napraw.
kondziu_mentioned = False
for mention in message.mentions:
if mention == client.user:
kondziu_mentioned = True
if kondziu_mentioned or "conjurer:" in message.content: if "conjurer:" in message.content:
async with channel.typing(): async with channel.typing():
logger.debug("Procedura chatu") logger.debug("Procedura chatu")
@@ -335,29 +323,6 @@ async def on_message(message):
# *=========================================== Define Functions # *=========================================== Define Functions
def num_tokens_from_string(message, model):
"""
The function takes a string message and a model as input and returns the number of tokens in the
message according to the given model.
:param message: A string containing the message or text from which you want to count the number of
tokens
:param model: The model parameter refers to a language model or tokenizer that can be used to
tokenize the input string. It could be a pre-trained model or a custom tokenizer
"""
tokens_per_message = 3
tokens_per_name = 1
chat_gpt_encoding = tiktoken.encoding_for_model(model)
num_tokens = 0
num_tokens += tokens_per_message
for keys, values in message.items():
num_tokens += len(chat_gpt_encoding.encode(values))
if keys == "role":
num_tokens += tokens_per_name
num_tokens += 3 # every reply is primed with <|start|>assistant<|message|>
return num_tokens
async def connect(ctx, arg=None): async def connect(ctx, arg=None):
""" """
@@ -488,18 +453,24 @@ async def play(ctx, zamawial=None, arg=None):
await ctx.send(result) await ctx.send(result)
async def archive_channel(channel_no):
channel = client.get_channel(channel_no)
messages = [message async for message in channel.history(limit=None)]
path_newfile = (
f"{LOGSTORE}channeldump_{channel_no}_{datetime.now()}.json"
)
new_data = []
for message in messages:
pass
with open(path_newfile, "x", encoding=ENCODING) as new_file:
new_file.seek(0)
json.dump(new_data, new_file, indent=4)
async def check(): async def check():
"""Funkcja sprawdzająca czy grać następny kawałek.""" """Funkcja sprawdzająca czy grać następny kawałek."""
last_spontaneous_call = datetime.now()
while True: while True:
tdelta = datetime.now() - last_spontaneous_call # TODO: Tu dołożyć skanowanie rozmiaru pliku logowania oraz plików pamięci i przenoszenie ich na większy dysk.
tdelta = tdelta.total_seconds()
if tdelta > 34000:
channel = client.get_channel(1062047571557744721)
last_spontaneous_call = datetime.now()
with channel.typing():
message = get_random_cyclic_message()
await channel.send(message)
# trunk-ignore(codespell/misspelled) # trunk-ignore(codespell/misspelled)
# TODO: dlaczego sie tu wypierdala # TODO: dlaczego sie tu wypierdala
if client.voice_clients: if client.voice_clients:
@@ -567,19 +538,7 @@ async def check():
await asyncio.sleep(60) await asyncio.sleep(60)
async def get_random_cyclic_message():
"""
The function `get_random_cyclic_message` returns a random cyclic message from a list of cyclic
words.
:return: a random cyclic message from the list `cyclic_words`.
"""
messnum = random.randint(0, len(cyclic_words)-1)
return cyclic_words[messnum][0]
# trunk-ignore(pylint/R0914)
# trunk-ignore(pylint/R0913) # trunk-ignore(pylint/R0913)
# trunk-ignore(pylint/R0915)
async def handle_response(prompt, vykidailo, bartender, history, username, music): async def handle_response(prompt, vykidailo, bartender, history, username, music):
""" """
Handle responses by appending them to a history, use OpenAI to Handle responses by appending them to a history, use OpenAI to
@@ -622,49 +581,22 @@ async def handle_response(prompt, vykidailo, bartender, history, username, music
# convert back to json. # convert back to json.
json.dump(file_data, file_memory, indent=4) json.dump(file_data, file_memory, indent=4)
history = [] history = []
history.append(GPT_SETTINGS[0]) # * append bo pierwszy index
chat_gpt_config_request_size = num_tokens_from_string(GPT_SETTINGS[0], "gpt-4") # * extend bo 20 ostatnich
for (slowo, reakcja) in word_reactions.items():
if not reakcja[3]:
content = "Kiedy słyszysz " + slowo + " to reagujesz lub dzieje się to " + reakcja[0]
temp = {"role": "system", "content": content}
chat_gpt_config_request_size += num_tokens_from_string(temp, "gpt-4")
history.append(temp)
final_prompt = username + ":" + prompt
logger.info("Rozmiar zapytania przed dodaniem historii %s", chat_gpt_config_request_size)
if music: if music:
algorithm = "gpt-3.5-turbo-16k" history.append(message_table_muzyka[0])
table = message_table_muzyka history.extend(message_table_muzyka[-15:])
token_amount = 10700
else: else:
table = MESSAGE_TABLE history.append(MESSAGE_TABLE[0])
algorithm = "gpt-4" history.extend(MESSAGE_TABLE[-15:])
token_amount = 7000
prompt_gpt_request_size = num_tokens_from_string({"role": "user", "content": final_prompt}, "gpt-4")
temptable = []
for i in reversed(table):
temp_token = num_tokens_from_string(i, "gpt-4")
logger.info("Rozmiar zapytania %s prompt %s temp %s", chat_gpt_config_request_size, prompt_gpt_request_size, temp_token)
if chat_gpt_config_request_size < token_amount + prompt_gpt_request_size + temp_token:
temptable.insert(1, i)
chat_gpt_config_request_size += temp_token
history.extend(temptable)
temp = {"role": "user", "content": final_prompt}
history.append(temp)
logger.info("Rozmiar zapytania po wyslaniu %s", chat_gpt_config_request_size)
response = await openai.ChatCompletion.acreate(
model=algorithm, messages=history
)
logger.info("Historia wysłana:") logger.info("Historia wysłana:")
logger.info(history) logger.debug(history)
await asyncio.sleep(15) response = await openai.ChatCompletion.acreate(
model="gpt-4", messages=history
)
await asyncio.sleep(10)
result = "" result = ""
logger.debug("Odpowiedzi") logger.debug("Odpowiedzi")
logger.info(response)
logger.debug(response.choices) logger.debug(response.choices)
for choice in response.choices: for choice in response.choices:
result += choice.message.content result += choice.message.content
@@ -940,7 +872,7 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
all_words = [] all_words = []
async for f_iter in async_iterator_generator(file): async for f_iter in async_iterator_generator(file):
async for char in async_iterator_generator(char_remove): async for char in async_iterator_generator(char_remove):
f_iter = await remove_characters(f_iter, char) f_iter = f_iter.replace(char, "")
tmp = f_iter.split() tmp = f_iter.split()
all_words.extend(tmp) all_words.extend(tmp)
pingu = 1 pingu = 1
@@ -986,18 +918,6 @@ async def wyszukaj(ctx, how_many=0, slowa_kluczowe=None):
return return_list return return_list
async def remove_characters(string, character):
"""
The `remove_characters` function removes all occurrences of a specified character from a given
string.
:param string: The string parameter is the input string from which characters will be removed
:param character: The character parameter is the character that you want to remove from the string
:return: a new string where all occurrences of the specified character have been removed.
"""
return string.replace(character, "")
async def max_weight(lista): async def max_weight(lista):
""" """
Take a list of weights and return the maximum weight. Take a list of weights and return the maximum weight.
@@ -1455,7 +1375,7 @@ async def zrob_mi_plejliste(ctx):
if metadata.tag.title: if metadata.tag.title:
reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n" reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
else: else:
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera.\n" reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera."
index += 1 index += 1
if len(reply) > 1800: if len(reply) > 1800:
@@ -1632,7 +1552,6 @@ async def get_image_stable_diffusion(ctx):
guild=discord.Object(id=664789470779932693), guild=discord.Object(id=664789470779932693),
) )
# trunk-ignore(pylint/R0912) # trunk-ignore(pylint/R0912)
# trunk-ignore(pylint/R0915)
async def zagraj_muzyke_mego_ludu(ctx): async def zagraj_muzyke_mego_ludu(ctx):
""" """
Play completeley random playlist based on messaging history. Play completeley random playlist based on messaging history.
@@ -1644,31 +1563,22 @@ async def zagraj_muzyke_mego_ludu(ctx):
""" """
stats = {} stats = {}
if ctx: if ctx:
logger.info("Zagraj muzyke mego ludu: wywolane")
stat_iter = get_stats(ctx, MUZYKA_MOJEGO_LUDU_HISTORIA) stat_iter = get_stats(ctx, MUZYKA_MOJEGO_LUDU_HISTORIA)
async for name, how_many in stat_iter: async for name, how_many in stat_iter:
if len(name) > 3: if len(name) > 3:
stats[name] = how_many stats[name] = how_many
sorted_stats = sorted(stats.items(), key=lambda x: x[1]) sorted_stats = sorted(stats.items(), key=lambda x: x[1])
logger.info("Zagraj muzyke mego ludu:zebrano statystyki")
key_words = [] key_words = []
for stat in sorted_stats: for stat in sorted_stats:
key_words.append(stat[0]) key_words.append(stat[0])
logger.info(sorted_stats[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE]) logger.info(sorted_stats[:30])
logger.info(key_words[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE]) logger.info(key_words[:30])
logger.info(sorted_stats[-MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE:])
logger.info(key_words[-MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE:])
final_key_words = key_words[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE]
final_key_words.extend(key_words[-MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE:])
reply = "Wygenerowana plejlista:\n" reply = "Wygenerowana plejlista:\n"
async with ctx.typing(): async with ctx.typing():
logger.info("Zaczynam szukać timestamp %s", datetime.now()) logger.info("Zaczynam szukać timestamp %s", datetime.now())
search_time_glob = datetime.now() search_time_glob = datetime.now()
file = await wyszukaj(ctx=ctx, how_many=MUZYKA_MOJEGO_LUDU_PLAJLISTA, slowa_kluczowe=final_key_words) file = await wyszukaj(ctx=ctx, how_many=MUZYKA_MOJEGO_LUDU_PLAJLISTA, slowa_kluczowe=key_words[:MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE])
logger.info("Zagraj muzyke mego ludu:wygenerowano plejliste")
logger.info(file)
logger.info( logger.info(
"Koniec szukania(timestamp %s zajęło %s", "Koniec szukania(timestamp %s zajęło %s",
datetime.now(), datetime.now(),
@@ -1694,7 +1604,7 @@ async def zagraj_muzyke_mego_ludu(ctx):
if metadata.tag.title: if metadata.tag.title:
reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n" reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
else: else:
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera.\n" reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera."
index += 1 index += 1
if len(reply) > 1800: if len(reply) > 1800:
@@ -1714,7 +1624,7 @@ async def zagraj_muzyke_mego_ludu(ctx):
description="Konfiguruje komende zagraj muzyke mojego ludu", description="Konfiguruje komende zagraj muzyke mojego ludu",
guild=discord.Object(id=664789470779932693), guild=discord.Object(id=664789470779932693),
) )
async def parametry_muzyki_mego_ludu(ctx, ile_historii=1500, ile_slow_kluczowych=15, jak_dluga_plejlista=30): async def parametry_muzyki_mego_ludu(ctx, ile_historii=1500, ile_slow_kluczowych=30, jak_dluga_plejlista=30):
""" """
The function `parametry_muzyki_mego_ludu` sets global variables for the number of history entries, The function `parametry_muzyki_mego_ludu` sets global variables for the number of history entries,
number of keywords, and length of playlist for a music application. number of keywords, and length of playlist for a music application.
@@ -1732,27 +1642,12 @@ async def parametry_muzyki_mego_ludu(ctx, ile_historii=1500, ile_slow_kluczowych
""" """
if ctx: if ctx:
async with ctx.typing(): global MUZYKA_MOJEGO_LUDU_HISTORIA # pylint: disable=global-statement
# if ':' in ile_historii: MUZYKA_MOJEGO_LUDU_HISTORIA = ile_historii
# _, _, ile_historii = ile_historii.partition(':') global MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE # pylint: disable=global-statement
# if ':' in ile_slow_kluczowych: MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = ile_slow_kluczowych
# _, _, ile_slow_kluczowych = ile_slow_kluczowych.partition(':') global MUZYKA_MOJEGO_LUDU_PLAJLISTA # pylint: disable=global-statement
# if ':' in jak_dluga_plejlista: MUZYKA_MOJEGO_LUDU_PLAJLISTA = jak_dluga_plejlista
# _, _, jak_dluga_plejlista = jak_dluga_plejlista.partition(':')
try:
global MUZYKA_MOJEGO_LUDU_HISTORIA # pylint: disable=global-statement
global MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE # pylint: disable=global-statement
global MUZYKA_MOJEGO_LUDU_PLAJLISTA # pylint: disable=global-statement
logger.info("Długość historii wyszukiwania: %s\n Ilość słów kluczowych: %s\n Długość plejlisty do wygenerowanie: %s", MUZYKA_MOJEGO_LUDU_HISTORIA, MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE, MUZYKA_MOJEGO_LUDU_PLAJLISTA)
ctx.send(f"Dotychczasowe wartośći:\n Długość historii wyszukiwania: {MUZYKA_MOJEGO_LUDU_HISTORIA}\n Ilość słów kluczowych: {MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE}\n Długość plejlisty do wygenerowanie:{MUZYKA_MOJEGO_LUDU_PLAJLISTA}")
MUZYKA_MOJEGO_LUDU_HISTORIA = ile_historii
MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE = ile_slow_kluczowych
MUZYKA_MOJEGO_LUDU_PLAJLISTA = jak_dluga_plejlista
logger.info("Długość historii wyszukiwania: %s\n Ilość słów kluczowych: %s\n Długość plejlisty do wygenerowanie: %s", MUZYKA_MOJEGO_LUDU_HISTORIA, MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE, MUZYKA_MOJEGO_LUDU_PLAJLISTA)
ctx.send(f"Zmienione wartośći:\n Długość historii wyszukiwania: {MUZYKA_MOJEGO_LUDU_HISTORIA}\n Ilość słów kluczowych: {MUZYKA_MOJEGO_LUDU_SLOWA_KLUCZOWE}\n Długość plejlisty do wygenerowanie:{MUZYKA_MOJEGO_LUDU_PLAJLISTA}")
except discord.ext.commands.errors.BadArgument as exce:
ctx.send("Spierdalaj")
logger.info(exce)
# *================================== Run # *================================== Run
+1707
View File
File diff suppressed because it is too large Load Diff
+58
View File
@@ -0,0 +1,58 @@
# trunk-ignore-all(pylint/C0301)
FILE_SIZE_LIMIT = 100000 * 1024
SOURCE = "/mnt/n/scimag_2020-05-30.sql/scimag_2020-05-30.sql"
OUTPUT_FOLDER = "/mnt/n/scimag_2020-05-30.sql/"
OUTPUT_FILE_SCHEMA = "_scimag_chunk.sql"
def smart_write(lines, file):
"""
The function `smart_write` encodes the input lines to UTF-8, writes them to a file, and returns the
size of the encoded bytes.
:param lines: The `lines` parameter in the `smart_write` function is a string that contains the text
content that you want to write to a file
:param file: The `file` parameter in the `smart_write` function is expected to be a file object that
has been opened in write mode. This file object will be used to write the encoded `lines` to a file
:return: The function `smart_write` returns the size of the encoded bytes of the input `lines` in
bytes.
"""
encoded_bytes = lines.encode("utf-8")
size_in_bytes = len(encoded_bytes)
file.write(lines)
return size_in_bytes
def cut_my_life_into_pieces(source, output_folder, output_file):
"""
The function `cut_my_life_into_pieces` reads a source file, splits its content into smaller parts
based on a file size limit, and writes these parts to separate output files in a specified output
folder.
:param source: The `source` parameter in the `cut_my_life_into_pieces` function is the file path of
the source file that you want to process and split into smaller pieces
:param output_folder: The `output_folder` parameter in the `cut_my_life_into_pieces` function
represents the directory where the output files will be saved. It should be a string that specifies
the path to the folder where you want to store the output files generated by the function. For
example, it could be something like
:param output_file: The `output_file` parameter in the `cut_my_life_into_pieces` function represents
the name of the output file that will be created for each segment of the source file. It will be
appended with a number to differentiate between different segments
"""
with open(source, encoding="utf-8") as infile:
output_size = 0
output_no = 0
for line in infile:
if output_size > FILE_SIZE_LIMIT:
output_no += 1
output_size = 0
op_file_name = str(output_no) + output_file
with open(
output_folder + op_file_name,
"a",
encoding="utf-8",
) as op_file:
output_size += smart_write(line, op_file)
+33
View File
@@ -0,0 +1,33 @@
"""
Kluczowe jest zeby po każdej linijce pokazywał która to jest, oraz po pliku
"""
import netrc
import mysql.connector
NETRC_FILE = "/home/mtuszowski/.netrc"
netrc_mod = netrc.netrc(NETRC_FILE)
REMOTE_HOST_NAME = "sql_localhost"
authTokens = netrc_mod.authenticators(REMOTE_HOST_NAME)
mydb = mysql.connector.connect(
host="localhost", user="root", password="root", database="scihubdois"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM scimag")
for x in mycursor:
print(x)
file_list = ""
for file in file_list:
with open(
"/mnt/n/scimag_2020-05-30.sql/{}".format(file), encoding="utf-8"
) as infile:
pass
result = mycursor.execute("SHOW databases")
# trunk-ignore(mypy/union-attr)
+35
View File
@@ -0,0 +1,35 @@
from pathlib import Path, PurePath
from platform import uname
from sys import platform
MUSIC_FOLDER = ""
if platform in ("linux", "linux2"):
SEPARATOR_FILE_PATH = "/"
if "microsoft-standard" in uname().release:
LOGFILE = "/home/mtuszowski/conjurer/discord_mus_service.log"
MUSIC_FOLDER = "/mnt/g/Muzyka/"
NETRC_FILE = "/home/mtuszowski/.netrc"
LOGSTORE = "/home/mtuszowski/conjurer/logs/"
ENCODING = "utf-8"
GRAPHICS_PATH = "/home/mtuszowski/conjurer/Conjurer_graphics/"
else:
LOGFILE = "/home/pi/Conjurer/discord_mus_service.log"
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json"
SYSTEM_GPT_SETTINGS = "/home/pi/Conjurer/system_gpt_settings.json"
MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json"
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"
ENCODING = "utf-8"
GRAPHICS_PATH = "/home/pi/RetroPie/Conjurer_graphics/"
DIR_PATH_SADOX = "/home/pi/RetroPie/Fansadox/"
music_file_list = []
for mp3_item in Path.glob(Path(MUSIC_FOLDER), "**/*.mp3"):
temp_music_file = mp3_item.as_posix()
if platform == "win32":
temp_music_file = temp_music_file.replace("/", "\\")
music_file_list.append(temp_music_file)
+1 -1
View File
@@ -211,7 +211,7 @@
false, false,
false false
], ],
"burdel": [ "burdel\\b": [
"Oooo... Hammer nadal nie zmienił firanek - ale całkiem nieźle sprząta, jebaniutki.", "Oooo... Hammer nadal nie zmienił firanek - ale całkiem nieźle sprząta, jebaniutki.",
15.0, 15.0,
0, 0,
+26
View File
@@ -0,0 +1,26 @@
"""
This Python code snippet is connecting to a MySQL database
using the `mysql.connector` library and fetching data from a table named `scimag`
Here is a breakdown of what the code is doing:
"""
import netrc
import mysql.connector
NETRC_FILE = "/home/mtuszowski/.netrc"
netrc_mod = netrc.netrc(NETRC_FILE)
REMOTE_HOST_NAME = "192.168.1.192"
authTokens = netrc_mod.authenticators(REMOTE_HOST_NAME)
mydb = mysql.connector.connect(
host=REMOTE_HOST_NAME,
user=authTokens[0],
password=authTokens[2],
database="scihubdois",
)
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM scimag WHERE Title Like 'spider%'")
for x in mycursor:
print(x)