Compare commits
No commits in common. "67f8339cd64978f7a675aad93fb65f10ee97a787" and "8a5cef4debe9978fafe540ee4c532565c32c775a" have entirely different histories.
67f8339cd6
...
8a5cef4deb
@ -296,8 +296,7 @@ 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" if it is not already in {language}, otherwise you just copy it."},
|
||||
f" you translate everything you get directly to {language}."},
|
||||
{"role": "user", "content": text}]
|
||||
try:
|
||||
result = await openai.ChatCompletion.acreate(model=self.config["fix-model"],
|
||||
|
||||
@ -4,10 +4,6 @@ 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
|
||||
@ -49,40 +45,11 @@ 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):
|
||||
@ -152,11 +119,7 @@ class FjerkroaBot(commands.Bot):
|
||||
return
|
||||
for ma_user in self._re_user.finditer(message_content):
|
||||
uid = int(ma_user.group(1))
|
||||
for guild in self.guilds:
|
||||
user = guild.get_member(uid)
|
||||
if user is not None:
|
||||
break
|
||||
if user is not None:
|
||||
user = message.guild.get_member(uid)
|
||||
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)
|
||||
@ -176,7 +139,6 @@ 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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user