This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
73 lines (58 loc) 路 2.15 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from twitchio.ext import commands
from rich.console import Console
from rich.traceback import install
install()
console = Console()
from mfs import *
class Bot(commands.Bot):
def __init__(self, token: str = None, prefix: str = "!", channels: [str] = []):
super().__init__(
token=token,
prefix=prefix,
initial_channels=channels,
)
self.prompt: str = None
self.messages: [dict] = [
{"role": "system", "content": "Answer as briefly as possible."}
]
async def event_ready(self):
console.log(f"Bot started as '{self.nick}'")
async def event_message(self, message):
if message.echo:
return
if message.content.startswith("!ai"):
givenPrompt: str = (
message.content.split(" ", 1)[1] if " " in message.content else None
)
self.prompt = givenPrompt if givenPrompt else None
console.log(f"{message.author.name} asked: {self.prompt}")
try:
await self.handle_commands(message)
except AttributeError:
pass
@commands.cooldown(rate=1, per=5, bucket=commands.Bucket.user)
@commands.command(aliases=["ai"])
async def processPrompt(self, ctx: commands.Context):
if self.prompt:
with console.status("Generating response..."):
response = generateResponse(self.prompt, self.messages)
"""
if logging:
write to logs
"""
partitionedText = (
splitMessage(response) if len(response) > 440 else [response]
)
for text in partitionedText:
await ctx.channel.send(f"{text} @{ctx.author.name}")
else:
console.log(
f"[red]Failed to generate message from {ctx.author.name} in {ctx.channel.name}[/]"
)
async def event_command_error(
self, context: commands.Context, error: Exception
) -> None:
pass
# TODO load config and features from files, check if config is empty and if so prompt to enter values that are missing
bot = Bot()
bot.run()