-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
80 lines (66 loc) · 3.36 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
74
75
76
77
78
79
80
# main.py
from agentforge.utils.DiscordClient import DiscordClient
import time
import yaml
from Modules.proccess_slash_command import SlashCommands
from Modules.process_indirect_message import IndirectMessage
from Modules.process_channel_message import ChannelMessage
from Modules.process_direct_message import DirectMessage
from Utilities.Memory import Memory
def process_message(message):
print(f"Processing message: {message}")
# Simulate some time-consuming task
time.sleep(5)
return f"Processed: -{message}- This process_message function should be replaced."
class Run:
def __init__(self):
self.client = DiscordClient()
self.client.run()
with open(".agentforge/personas/default.yaml", "r") as file:
self.persona = yaml.safe_load(file)
self.persona_name = self.persona.get("Name")
self.memory = Memory(self.persona, self.persona_name)
self.do_command = SlashCommands(self.memory, self.client)
self.indirect_message = IndirectMessage(self.memory)
self.direct_message = DirectMessage(self.memory, self.client)
self.channel_message = ChannelMessage(self.memory, self.client)
def main(self):
while True:
try:
for channel_id, messages in self.client.process_channel_messages():
for message in messages:
print(f"Message received: {message}")
function_name = message.get("function_name")
# Check if this is a /bot command
if function_name:
response = self.do_command.parse(message)
# self.client.send_message(channel_id, response)
self.client.send_embed(
channel_id=channel_id,
title="Command Result",
fields=[("Result", f"{response}")],
color='blue',
image_url=None)
# Check if the message is a DM
elif message['channel'].startswith('Direct Message'):
# If it's a DM, use the author's ID to send a DM back
response = self.direct_message.process_message(message)
self.client.send_dm(message['author_id'].id, response)
else:
# Check if bot is mentioned in the message
mentioned = any(mention.name == self.persona_name for mention in message['mentions'])
if mentioned:
# If bot is @ mentioned, send the response to the channel
# 'Name' in persona must match discord display name.
response = self.channel_message.process_message(message)
self.client.send_message(channel_id, response)
else:
self.indirect_message.process_message(message)
print('That message was not for me.')
except Exception as e:
print(f"An error occurred: {e}")
finally:
time.sleep(5)
if __name__ == "__main__":
run = Run()
run.main()