Compare commits

..

2 Commits

2 changed files with 42 additions and 3 deletions

View File

@ -296,7 +296,8 @@ class AIResponder(object):
if 'fix-model' not in self.config:
return text
message = [{"role": "system", "content": f"You are an professional translator to {language} language,"
f" you translate everything you get directly to {language}."},
f" you translate everything you get directly to {language}"
f" if it is not already in {language}, otherwise you just copy it."},
{"role": "user", "content": text}]
try:
result = await openai.ChatCompletion.acreate(model=self.config["fix-model"],

View File

@ -4,6 +4,10 @@ import tomlkit
import discord
import logging
import re
import random
import time
import asyncio
import math
from discord import Message, TextChannel, DMChannel
from discord.ext import commands
from watchdog.observers import Observer
@ -45,11 +49,40 @@ class FjerkroaBot(commands.Bot):
self.aichannels = {chan_name: AIResponder(self.config, chan_name) for chan_name in self.config['additional-responders']}
def init_channels(self):
if 'chat-channel' in self.config:
self.chat_channel = self.channel_by_name(self.config['chat-channel'], no_ignore=True)
self.staff_channel = self.channel_by_name(self.config['staff-channel'], no_ignore=True)
self.welcome_channel = self.channel_by_name(self.config['welcome-channel'], no_ignore=True)
def init_boreness(self):
if 'chat-channel' not in self.config:
return
self.last_activity_time = 0.0
self.loop.create_task(self.on_boreness())
logging.info('Boreness initialised.')
async def on_boreness(self):
logging.info(f'Boreness started on channel: {repr(self.chat_channel)}')
while True:
if self.chat_channel is None:
await asyncio.sleep(7)
continue
boreness_interval = float(self.config.get('boreness-interval', 12.0))
elapsed_time = (time.monotonic() - self.last_activity_time) / 3600.0
probability = 1 / (1 + math.exp(-1 * (elapsed_time - (boreness_interval / 2.0)) + math.log(1 / 0.2 - 1)))
if random.random() < probability:
logging.info(f'Borred with {probability} probability after {elapsed_time}')
boreness_prompt = self.config.get('boreness-prompt', 'Pretend that you just now thought of something, be creative.')
message = AIMessage('system', boreness_prompt, self.config.get('chat-channel', 'chat'), True)
try:
await self.respond(message, self.chat_channel)
except Exception as err:
logging.warning(f"Failed to activate borringness: {repr(err)}")
await asyncio.sleep(7)
async def on_ready(self):
self.init_channels()
self.init_boreness()
logging.info(f"We have logged in as {self.user} ({repr(self.staff_channel)}, {repr(self.welcome_channel)})")
async def on_member_join(self, member):
@ -119,8 +152,12 @@ class FjerkroaBot(commands.Bot):
return
for ma_user in self._re_user.finditer(message_content):
uid = int(ma_user.group(1))
user = message.guild.get_member(uid)
message_content = re.sub(f'[<][@][!]? *{uid} *[>]', f'@{user.name}', message_content)
for guild in self.guilds:
user = guild.get_member(uid)
if user is not None:
break
if user is not None:
message_content = re.sub(f'[<][@][!]? *{uid} *[>]', f'@{user.name}', message_content)
channel_name = self.get_channel_name(message.channel)
msg = AIMessage(message.author.name, message_content, channel_name, self.user in message.mentions)
await self.respond(msg, message.channel)
@ -139,6 +176,7 @@ class FjerkroaBot(commands.Bot):
await answer_channel.send(response.answer, files=images, suppress_embeds=True)
else:
await answer_channel.send(response.answer, suppress_embeds=True)
self.last_activity_time = time.monotonic()
async def respond(
self,