Work ongoing - rich presence and ai assistant

This commit is contained in:
2024-11-14 19:53:40 +01:00
parent 14b9a50f51
commit b15c2f06b8
5 changed files with 79 additions and 53 deletions
+19 -10
View File
@@ -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,11 +67,21 @@ class Events(commands.Cog):
return
if isinstance(message.channel, discord.DMChannel):
if message.author.id == 346956223645614080:
await ai_functions.hammer_assitant_chat(message)
# 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}")
# 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
@@ -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,
+9 -6
View File
@@ -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,16 +295,19 @@ 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"}]
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
id = 346956223645614080
@@ -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}")
+7 -5
View File
@@ -619,7 +619,9 @@ 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(
ctx, "Youtube", link
@@ -628,7 +630,9 @@ class MusicModule(commands.Cog):
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,7 +672,6 @@ 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(
@@ -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")
+27 -3
View File
@@ -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 = []
+6 -18
View File
@@ -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"))
logger.info("Logged in as ---->", client.user)
logger.info("ID:", client.user.id)
# TODO: ADMINISTRATION