Small fixes in the paths

This commit is contained in:
2023-06-22 23:19:59 +02:00
parent 522d2f64b0
commit b464ebb7aa
+33 -37
View File
@@ -24,7 +24,7 @@ from logging import handlers
from pathlib import Path, PurePath from pathlib import Path, PurePath
from platform import uname from platform import uname
from sys import platform from sys import platform
from typing import List, TypedDict, Union from typing import List, TypedDict, Optional
# *==============Imported libraries # *==============Imported libraries
import discord import discord
@@ -49,7 +49,7 @@ Music_Config = TypedDict(
"Music_Config", "Music_Config",
{ {
"playing": bool, "playing": bool,
"ctx": Union[str, None], "ctx": Optional[str],
"queue": List[str], "queue": List[str],
"requestor": List[str], "requestor": List[str],
}, },
@@ -72,16 +72,18 @@ GRAPHICS_PATH = ""
# *=========================================== Platform Specific Predefines # *=========================================== Platform Specific Predefines
if platform in ("linux", "linux2"): if platform in ("linux", "linux2"):
if "microsoft-standard" in uname().release: if "microsoft-standard" in uname().release:
LOGFILE = "/home/pi/Conjurer/discord.log" LOGFILE = "/home/mtuszowski/conjurer/discord.log"
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json" MEMORY_FIVE_SIARA = "/home/mtuszowski/conjurer/pamiec.json"
MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json" MEMORY_FIVE_MUZYKA = "/home/mtuszowski/conjurer/pamiec_muzyki.json"
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/" MUSIC_FOLDER = "/mnt/g/Muzyka/"
SETTINGS_FILE = "/home/pi/Conjurer/settings.json" SETTINGS_FILE = "/home/mtuszowski/conjurer/settings.json"
NETRC_FILE = "/home/pi/netrc" NETRC_FILE = "/home/mtuszowski/.netrc"
LOGSTORE = "/home/pi/RetroPie/logs/" LOGSTORE = "/home/mtuszowski/conjurer/logs/"
ACCIDENT_LOG = "/home/pi/Conjurer/accident_log.json" ACCIDENT_LOG = "/home/mtuszowski/conjurer/accident_log.json"
ENCODING = "utf-8" ENCODING = "utf-8"
GRAPHICS_PATH = "/home/pi/RetroPie/Conjurer_graphics/" GRAPHICS_PATH = "/home/mtuszowski/conjurer/Conjurer_graphics/"
DIR_PATH_SADOX = "/mnt/c/Users/mtusz/OneDrive/Dokumenty/Fansadox"
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"
@@ -93,6 +95,8 @@ if platform in ("linux", "linux2"):
ACCIDENT_LOG = "/home/pi/Conjurer/accident_log.json" ACCIDENT_LOG = "/home/pi/Conjurer/accident_log.json"
ENCODING = "utf-8" ENCODING = "utf-8"
GRAPHICS_PATH = "/home/pi/RetroPie/Conjurer_graphics/" GRAPHICS_PATH = "/home/pi/RetroPie/Conjurer_graphics/"
DIR_PATH_SADOX = "/home/pi/RetroPie/Fansadox/"
elif platform == "win32": elif platform == "win32":
LOGFILE = "discord.log" LOGFILE = "discord.log"
@@ -103,7 +107,9 @@ elif platform == "win32":
NETRC_FILE = "C:\\Users\\mtusz\\.netrc" NETRC_FILE = "C:\\Users\\mtusz\\.netrc"
LOGSTORE = "C:\\Users\\mtusz\\OneDrive\\Pulpit\\Conjurer\\logs\\" LOGSTORE = "C:\\Users\\mtusz\\OneDrive\\Pulpit\\Conjurer\\logs\\"
ACCIDENT_LOG = "accident_log.json" ACCIDENT_LOG = "accident_log.json"
ENCODING = "cp1250" ENCODING = "utf-8"
DIR_PATH_SADOX = "C:\\Users\\mtusz\\OneDrive\\Dokumenty\\Fansadox\\"
# *=========================================== Keys # *=========================================== Keys
netrc_mod = netrc.netrc(NETRC_FILE) netrc_mod = netrc.netrc(NETRC_FILE)
@@ -436,7 +442,7 @@ async def play(ctx, zamawial=None, arg=None):
username = ctx.message.author.nick username = ctx.message.author.nick
else: else:
username = ctx.message.author.name username = ctx.message.author.name
global MESSAGE_TABLE # pylint: disable=global-statement global MESSAGE_TABLE # pylint: disable=global-statement
result, MESSAGE_TABLE = await handle_response( result, MESSAGE_TABLE = await handle_response(
query, vykidailo, bartender, message_table_muzyka, username, True query, vykidailo, bartender, message_table_muzyka, username, True
) )
@@ -517,9 +523,7 @@ async def check():
# trunk-ignore(pylint/R0913) # trunk-ignore(pylint/R0913)
async def handle_response( async def handle_response(prompt, vykidailo, bartender, history, username, music):
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
generate a response, and then append the generated response to the history. generate a response, and then append the generated response to the history.
@@ -745,7 +749,7 @@ async def async_iterator_generator(range_of_iterable):
# pylint: disable=pointless-string-statement # pylint: disable=pointless-string-statement
# yield the result # yield the result
yield i yield i
''' """
Alternatywna wersja przerobienia fora na asynchroniczny. Alternatywna wersja przerobienia fora na asynchroniczny.
# traverse the iterable of awaitables # traverse the iterable of awaitables
for item in coros: for item in coros:
@@ -753,7 +757,7 @@ async def async_iterator_generator(range_of_iterable):
result = await item result = await item
# report the results # report the results
print(result) print(result)
''' """
# trunk-ignore(pylint/R0914) # trunk-ignore(pylint/R0914)
@@ -1069,27 +1073,22 @@ async def get_image_sadox(ctx):
logger.info("Get sadox") logger.info("Get sadox")
channel = ctx.message.channel channel = ctx.message.channel
async with channel.typing(): async with channel.typing():
dir_path_sadox = ""
# select random file # select random file
if platform in ("linux", "linux2"):
dir_path_sadox = "/home/pi/RetroPie/Fansadox/"
elif platform == "win32":
dir_path_sadox = "C:\\Users\\mtusz\\OneDrive\\Dokumenty\\Fansadox\\"
res = [] res = []
# Iterate directory # Iterate directory
for path in os.listdir(dir_path_sadox): for path in os.listdir(DIR_PATH_SADOX):
# check if current path is a file # check if current path is a file
if os.path.isfile(os.path.join(dir_path_sadox, path)): if os.path.isfile(os.path.join(DIR_PATH_SADOX, path)):
res.append(path) res.append(path)
filename = res[random.randrange(0, len(res) - 1)] filename = res[random.randrange(0, len(res) - 1)]
# select random page # select random page
file = open(dir_path_sadox + filename, "rb") file = open(DIR_PATH_SADOX + filename, "rb")
readpdf = PyPDF2.PdfReader(file) readpdf = PyPDF2.PdfReader(file)
totalpages = len(readpdf.pages) totalpages = len(readpdf.pages)
page = random.randrange(1, totalpages) page = random.randrange(1, totalpages)
# convert page to image # convert page to image
image = pdf2image.convert_from_path( image = pdf2image.convert_from_path(
dir_path_sadox + filename, first_page=page, last_page=page DIR_PATH_SADOX + filename, first_page=page, last_page=page
) )
byte_io_stream = io.BytesIO() byte_io_stream = io.BytesIO()
image[0].save(byte_io_stream, "JPEG") image[0].save(byte_io_stream, "JPEG")
@@ -1321,9 +1320,7 @@ async def zrob_mi_plejliste(ctx):
if metadata.tag.album: if metadata.tag.album:
reply += f" z albumu {metadata.tag.album}" reply += f" z albumu {metadata.tag.album}"
if metadata.tag.title: if metadata.tag.title:
reply += ( reply += " z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
" z prywatnej kolekcji Hammera i na Twoją specjalną rpośbę.\n"
)
else: else:
reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera." reply += f"{index}. {plik[1]} z prywatnej kolekcji Hammera."
@@ -1343,17 +1340,16 @@ async def zrob_mi_plejliste(ctx):
@client.hybrid_command( @client.hybrid_command(
name="przytul", description="Przytul kogoś - daj mention po komendzie :)" name="przytul", description="Przytul kogoś - daj mention po komendzie :)"
) )
async def przytul(ctx, arg: Union[discord.Member, None] = None): async def przytul(ctx, arg: Optional[discord.Member] = None):
""" """
Generate a text about hugging mentioned user. Generate a text about hugging mentioned user.
:param ctx: ctx stands for "context" and is a required parameter in Discord.py commands. It :param ctx: ctx stands for "context" and is a required parameter in Discord.py commands. It
represents the context in which the command is being executed, including information such as the represents the context in which the command was invoked, including information such as the message,
message, the channel, the server, and the user who invoked the command the channel, the server, and the user who invoked the command
:param arg: The parameter "arg" is a variable that can accept either a discord.Member object or None :param arg: arg is a parameter of the function "przytul" that expects a Discord member object. The
as its value. It is an optional parameter, which means that if no value is provided for it when the parameter is optional, meaning that if no member object is provided, it will default to None
function is called, it will default to None :type arg: Optional[discord.Member]
:type arg: Union[discord.Member, None]
""" """
async with ctx.typing(): async with ctx.typing():
nieprzytulac = False nieprzytulac = False