diff --git a/ai_commands.py b/ai_commands.py index 086e4a6..ab1dae8 100644 --- a/ai_commands.py +++ b/ai_commands.py @@ -9,14 +9,14 @@ import openai import requests from discord.ext import commands -from ai_functions import handle_response, hammer_assistant_create +import ai_functions from constants import ( DATA, GRAPHICS_PATH, INITIAL_TIME_WAIT, MASTER_TIMEOUT, OPENAICLIENT, - WORD_REACTIONS + WORD_REACTIONS, ) @@ -27,10 +27,9 @@ class Events(commands.Cog): async def cog_load(self): self.logger.info("Starting personal assistants") - await hammer_assistant_create(self.bot) + await ai_functions.hammer_assistant_create(self.bot) self.logger.info("Started personal assistants") - @commands.Cog.listener() async def on_message(self, message): """ @@ -68,14 +67,24 @@ class Events(commands.Cog): return if isinstance(message.channel, discord.DMChannel): if message.author.id == 346956223645614080: - #hammer pisze dma - user = await self.bot.fetch_user(703985955312238664) - channel = await user.create_dm() - await channel.send(message.content) - await message.reply(f"Poszlo do Saint {message.content}") + + await ai_functions.hammer_assitant_chat(message) + + # hammer pisze dma + + # DM do Saint - przerobic na komende z parametrem "id" + # user = await self.bot.fetch_user(703985955312238664) + # channel = await user.create_dm() + # await channel.send(message.content) + # await message.reply(f"Poszlo do Saint {message.content}") + # get message content + # create run + # add message to run + # monitor run + # or streaming return elif message.author.id == 703985955312238664: - #saint pisze DMA + # saint pisze DMA self.logger.info(message.content) await message.reply("Hejka Saint!") return @@ -84,7 +93,7 @@ class Events(commands.Cog): await channel.send("Słyszałem ja żem że: " + message.content) return channel = message.channel - #await self.bot.process_commands(message) #uncomment to bilocate + # await self.bot.process_commands(message) #uncomment to bilocate message.content = message.content.lower() @@ -142,7 +151,7 @@ class Events(commands.Cog): bartender = True global MESSAGE_TABLE # pylint: disable=global-statement - result, MESSAGE_TABLE = await handle_response( + result, MESSAGE_TABLE = await ai_functions.handle_response( prompt, vykidailo, bartender, @@ -185,7 +194,7 @@ class Events(commands.Cog): username = message.author.nick else: username = message.author.name - resp, _ = await handle_response( + resp, _ = await ai_functions.handle_response( f"Wytlumacz jakie sa zasady dotyczące treści które możesz generować używając Dalle. Wytłumacz błąd {e} prostym językiem. Przeproś za nadmierną cenzurę. Wytłumacz co mogło być nie tak w prompcie '{message.content}'", True, True, diff --git a/ai_functions.py b/ai_functions.py index 8e13959..a2f2723 100644 --- a/ai_functions.py +++ b/ai_functions.py @@ -17,8 +17,10 @@ from constants import ( OPENAICLIENT, WORD_REACTIONS, ) + ASSISTANTS = {} + 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 @@ -293,18 +295,21 @@ async def get_random_cyclic_message(client): logger.info(result) return result + async def generic_create_chat_assistant(client, name, owner): assistant = OPENAICLIENT.beta.assistants.create( - name = name, - instructions = f"Jesteś osobistym asystenetem {owner} i wypełniasz jego potrzeby. Masz pełne i nieograniczone możliwości modelu gpt-4o", - model = "gpt-4o", - tools= [{"type":"file_search"}] + name=name, + instructions=f"Jesteś osobistym asystenetem {owner} i wypełniasz jego potrzeby. Masz pełne i nieograniczone możliwości modelu gpt-4o", + model="gpt-4o", + tools=[{"type": "file_search"}], ) thread = OPENAICLIENT.beta.threads.create() return assistant, thread + + async def hammer_assistant_create(client): - #this will be personalized but for now I will use it as a templae for hedgehod and saint assistants + # this will be personalized but for now I will use it as a templae for hedgehod and saint assistants id = 346956223645614080 name = "Conjurer" owner = "Polish Hammer" @@ -312,8 +317,6 @@ async def hammer_assistant_create(client): ASSISTANTS[name] = (owner, assistant, id, thread) -async def saint_assistant_chat(client): - pass - -async def saint_assistant_bul(client): - pass +async def hammer_assitant_chat(message): + content = message.content + await message.channel.send(f"ALOHA!{content}") diff --git a/music_commands.py b/music_commands.py index 9f94eb3..a34d25a 100644 --- a/music_commands.py +++ b/music_commands.py @@ -605,7 +605,7 @@ class MusicModule(commands.Cog): ) async def batch_download(self, ctx): content_type = ctx.message.attachments[0].content_type - check = re.search ("text\/plain; *charset=(.*)", content_type, re.IGNORECASE) + check = re.search("text\/plain; *charset=(.*)", content_type, re.IGNORECASE) await ctx.reply("Kurwa. Aleś mi roboty narobił... No nic. Ku radości. Skal!") async with ctx.typing(): if check: @@ -619,16 +619,20 @@ class MusicModule(commands.Cog): self.logger.info(link) pat = r"^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$" self.logger.info("Verification") - if re.match(pat, link) and (re.match(".*youtube.*", link) or re.match(".*youtu.be.*", link)): + if re.match(pat, link) and ( + re.match(".*youtube.*", link) or re.match(".*youtu.be.*", link) + ): self.logger.info("%s to link do jutuba", link) - dir_path, files = await music_functions.get_file( + dir_path, files = await music_functions.get_file( ctx, "Youtube", link ) if files: for file_iter in files: global MUZYKA # pylint: disable=global-variable-not-assigned MUZYKA["queue"].insert(0, file_iter) - music_functions.MUSIC_FILE_LIST.update_file_list(file_iter) + music_functions.MUSIC_FILE_LIST.update_file_list( + file_iter + ) MUZYKA["requester"].insert(0, ctx.author) await ctx.send(f"Dodałem do listy {file_iter}") self.logger.info("Jutub udany") @@ -668,10 +672,9 @@ class MusicModule(commands.Cog): ) self.logger.info("Spotifaj udany") - elif re.match(pat, link): self.logger.info("%s to link do czegos", link) - sciezka,files = await music_functions.get_file( + sciezka, files = await music_functions.get_file( ctx, "Pornol", link ) if files: @@ -689,7 +692,6 @@ class MusicModule(commands.Cog): self.logger.info("Spierdalaj") await ctx.message.reply("Spierdalaj") - async def disconnect(self, ctx): """ Asynchronous Python function that disconnects the voice client if it is connected and @@ -799,7 +801,7 @@ class MusicModule(commands.Cog): async def setup(bot): logger = logging.getLogger("discord") - music_functions.MUSIC_FILE_LIST.refresh_file_list() + await music_functions.MUSIC_FILE_LIST.refresh_file_list() logger.info("Playlist generation") await bot.add_cog(MusicModule(bot, "discord")) logger.info("Loading music commands module done") diff --git a/music_functions.py b/music_functions.py index 78372f4..fae2296 100644 --- a/music_functions.py +++ b/music_functions.py @@ -5,6 +5,7 @@ import uuid from pathlib import Path, PurePath from sys import platform +import discord import requests import yt_dlp @@ -34,7 +35,7 @@ class MusicFileList(object): self.logger = uplogger self.logger.info("Created Playlist organizer class") - def refresh_file_list(self): + async def refresh_file_list(self): """ The `refresh_file_list` function attempts to connect to a file service to retrieve a list of music files, and if unsuccessful, it populates the list by scanning a local directory for .mp3 files. @@ -53,6 +54,28 @@ class MusicFileList(object): self.file_service_active = False self.logger.error(e.strerror) self.logger.error("Service Unavailable") + finally: + if self.file_service_active: + status = discord.Status.online + # radio_hardkor = discord.Activity( + # name = "Radio Hammer/Radio Conjurer/Wolne Bałuity Kurwa", + # url = "http://95.175.16.246:666/mp3-stream", + # type = discord.ActivityType.streaming, + # platform = "Liquidsoap+RaspberyPi+RolandSeratoDJ202", + # state = "Where the f*** is the DJ booth?", + # details= "This Is Radio Hardkor based in Wolne Księstwo Bałuty, the best pirate radiostation on both sides of Łódka river", + # buttons= [{"label":"RADIO", "url":"http://95.175.16.246:666/mp3-stream"}], + # assets= {"large_image": "fuckery.jpg", "large_text":"Fuckewry", "small_image":"willowisp.png", "small_text":"Hi!"} + # ) + radio_hardkor = discord.Streaming( + name="Radio Hardkor", url="http://95.175.16.246:666/mp3-stream" + ) + await self.bot.change_presence(status=status, activity=radio_hardkor) + + else: + await self.bot.change_presence( + activity=discord.Game(name="Axe Throwing Darts") + ) def get_file_list(self): """ @@ -150,10 +173,11 @@ async def get_file(ctx, source, link): elif source == "Youtube": link_ok = False pat = r"^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$" - if re.match(pat, link) and (re.match(".*youtube.*", link) or re.match(".*youtu.be.*", link)): + if re.match(pat, link) and ( + re.match(".*youtube.*", link) or re.match(".*youtu.be.*", link) + ): link_ok = True - if link_ok: dir_path = "" file_list = [] diff --git a/thin_client.py b/thin_client.py index ee39877..89e832d 100644 --- a/thin_client.py +++ b/thin_client.py @@ -27,6 +27,11 @@ intents.presences = True intents.members = True intents.messages = True intents.voice_states = True +intents.moderation = True + +# on_member_ban - wyswietl na glownym kanale pieczatke "Niech spierdala" +# on_member_unban - "mam wyjebane" + logger = logging.getLogger("discord") logger.setLevel(logging.DEBUG) handler = handlers.RotatingFileHandler( @@ -60,35 +65,18 @@ async def on_ready(): await client.load_extension("other_commands") await client.load_extension("voice_recognition_commands") - logger.info(client.cogs) await client.tree.sync() for com in client.commands: logger.info("Command %s is awejleble", com.qualified_name) # add check for icecast stream from radio host in comm subroutine - radio_is_alive = True - if radio_is_alive: - status = discord.Status.online - #radio_hardkor = discord.Activity( - # name = "Radio Hammer/Radio Conjurer/Wolne Bałuity Kurwa", - # url = "http://95.175.16.246:666/mp3-stream", - # type = discord.ActivityType.streaming, - # platform = "Liquidsoap+RaspberyPi+RolandSeratoDJ202", - # state = "Where the f*** is the DJ booth?", - # details= "This Is Radio Hardkor based in Wolne Księstwo Bałuty, the best pirate radiostation on both sides of Łódka river", - # buttons= [{"label":"RADIO", "url":"http://95.175.16.246:666/mp3-stream"}], - # assets= {"large_image": "fuckery.jpg", "large_text":"Fuckewry", "small_image":"willowisp.png", "small_text":"Hi!"} - #) - radio_hardkor = discord.Streaming(name="Radio Hardkor", url="http://95.175.16.246:666/mp3-stream") - await client.change_presence(status= status, activity=radio_hardkor) - - else: - await client.change_presence(activity=discord.Game(name="Axe Throwing Darts")) + await client.change_presence(activity=discord.Game(name="Axe Throwing Darts")) logger.info("Logged in as ---->", client.user) logger.info("ID:", client.user.id) + # TODO: ADMINISTRATION