mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-17 07:12:09 +00:00
Tag: 1.21
Intermediate commits (oldest → newest): - Start of Armia Hammera - Enum fix - small fx - Optional argument fix - xxx - fix - Fix - ADdded smth - finished secret dm handling - bgfx - safe
This commit is contained in:
+65
-12
@@ -2,13 +2,16 @@
|
||||
import logging
|
||||
import re
|
||||
import sys
|
||||
from enum import Enum
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
import discord
|
||||
import openai
|
||||
import requests
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
import ai_functions
|
||||
from constants import (
|
||||
ASSISTANTS,
|
||||
@@ -19,12 +22,22 @@ from constants import (
|
||||
OPENAICLIENT,
|
||||
SPECJALNE_ZIEMNIACZKI,
|
||||
WORD_REACTIONS,
|
||||
MESSAGE_TABLE
|
||||
)
|
||||
DM_MODE = "assistant"
|
||||
class Dm_Mode(Enum):
|
||||
ARMIA_HAMMERA = 1,
|
||||
SPECJALNY_ZIEMNIACZEK = 2,
|
||||
SEKRETNY_SEKSRET = 3,
|
||||
ECHO_ECHO = 4
|
||||
|
||||
class Events(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.logger = logging.getLogger("discord")
|
||||
self.armia = {}
|
||||
for superfryta in SPECJALNE_ZIEMNIACZKI.values():
|
||||
self.armia[superfryta[0]] = Dm_Mode.SPECJALNY_ZIEMNIACZEK
|
||||
self.logger.info(self.armia)
|
||||
|
||||
async def cog_load(self):
|
||||
self.logger.info("Starting personal assistants")
|
||||
@@ -59,11 +72,40 @@ class Events(commands.Cog):
|
||||
description="Jeśli nie wiesz jak użyć tej komendy to nawet nie próbuj",
|
||||
guild=discord.Object(id=664789470779932693),
|
||||
)
|
||||
async def switch_dm_mode(self, ctx):
|
||||
if isinstance(ctx.channel, discord.DMChannel):
|
||||
pass
|
||||
#secrets, assistant, echo, dm
|
||||
#required parameter from list of values - assistant, dm_broadcast, echo
|
||||
async def switch_dm_mode(self, ctx, dm_mode_arg: Dm_Mode):
|
||||
async with ctx.channel.typing():
|
||||
if isinstance(ctx.channel, discord.DMChannel):
|
||||
for superfryta in SPECJALNE_ZIEMNIACZKI.values():
|
||||
if ctx.message.author.id == superfryta[0]:
|
||||
self.armia[superfryta[2]] = dm_mode_arg
|
||||
await ctx.reply("Weszlo")
|
||||
return
|
||||
await ctx.reply("Tylko członkowie Armii Hammera mogą używać. Nie jesteś jednym z nich")
|
||||
else:
|
||||
await ctx.reply("Nope. Nie wiesz jak użyć")
|
||||
|
||||
@commands.hybrid_command(
|
||||
name="armia_hammera",
|
||||
description="Jeśli nie wiesz jak użyć tej komendy to nawet nie próbuj"
|
||||
)
|
||||
async def armia_hammera(self, ctx, message_txt: str, recipient: Optional[discord.User]):
|
||||
await self.armia_hammera_back(ctx, message_txt, recipient)
|
||||
|
||||
async def armia_hammera_back(self, ctx, message_txt, recipient = None):
|
||||
recipients = []
|
||||
if recipient:
|
||||
recipients.append(recipient.id)
|
||||
else:
|
||||
for superfryta in SPECJALNE_ZIEMNIACZKI.values():
|
||||
recipients.append(superfryta[0])
|
||||
|
||||
for item in recipients:
|
||||
user = await self.bot.fetch_user(item)
|
||||
channel = await user.create_dm()
|
||||
self.logger.info("User %s -> %s: %s", ctx.message.author, user, message_txt)
|
||||
await channel.send(message_txt)
|
||||
await ctx.reply("Poszło")
|
||||
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message):
|
||||
@@ -105,15 +147,26 @@ class Events(commands.Cog):
|
||||
for superfryta in SPECJALNE_ZIEMNIACZKI.values():
|
||||
self.logger.info(superfryta[0])
|
||||
if message.author.id == superfryta[0]:
|
||||
await self.bot.process_commands(message)
|
||||
await ai_functions.chat_with_assistant(message, superfryta[1])
|
||||
return
|
||||
if self.armia[message.author.id]== Dm_Mode.SPECJALNY_ZIEMNIACZEK:
|
||||
await self.bot.process_commands(message)
|
||||
await ai_functions.chat_with_assistant(message, superfryta[1])
|
||||
return
|
||||
elif self.armia[message.author.id]== Dm_Mode.ECHO_ECHO:
|
||||
await ai_functions.echo(message)
|
||||
return
|
||||
elif self.armia[message.author.id]== Dm_Mode.ARMIA_HAMMERA:
|
||||
ctx = await self.bot.get_context(message)
|
||||
self.armia_hammera_back(ctx=ctx, message_txt=message.content)
|
||||
return
|
||||
elif self.armia[message.author.id]== Dm_Mode.SEKRETNY_SEKSRET:
|
||||
pass
|
||||
else:
|
||||
await message.channel.send("Coś się wyebao. Wołaj Hammera")
|
||||
return
|
||||
channel = self.bot.get_channel(1064888712565100614)
|
||||
#await channel.send("Słyszałem ja żem że: " + message.content)
|
||||
await channel.send("Słyszałem ja żem że: " + message.content)
|
||||
return
|
||||
channel = message.channel
|
||||
# await self.bot.process_commands(message) #uncomment to bilocate
|
||||
|
||||
message.content = message.content.lower()
|
||||
|
||||
tdelta = datetime.now() - MASTER_TIMEOUT
|
||||
|
||||
Reference in New Issue
Block a user