added experimental mood tracking and reactions based on message nature evaluation
This commit is contained in:
parent
1aa7cc0a1e
commit
a4540bd3d1
94
app.py
94
app.py
@ -24,7 +24,9 @@ attention = {}
|
|||||||
message_cache = {}
|
message_cache = {}
|
||||||
lock = False
|
lock = False
|
||||||
|
|
||||||
praise = 0
|
# -5 to 5
|
||||||
|
mood_happiness = 0
|
||||||
|
mood_energy = 0
|
||||||
|
|
||||||
model_settings_path = "model.json"
|
model_settings_path = "model.json"
|
||||||
model_settings = {
|
model_settings = {
|
||||||
@ -173,6 +175,29 @@ async def y_or_n(user_input, question):
|
|||||||
|
|
||||||
raise Exception("Answer provided does not begin with Y or N.")
|
raise Exception("Answer provided does not begin with Y or N.")
|
||||||
|
|
||||||
|
async def get_message_nature(user_input, pairings):
|
||||||
|
global formatter
|
||||||
|
|
||||||
|
context = "Analyze the conversation and answer the question as accurately as possible. Do not provide any commentary or extra help, you are programmed to respond with a single letter."
|
||||||
|
|
||||||
|
messages = []
|
||||||
|
|
||||||
|
if isinstance(user_input, list):
|
||||||
|
for i in user_input:
|
||||||
|
messages.append(i)
|
||||||
|
|
||||||
|
if isinstance(user_input, str):
|
||||||
|
messages.append({"author": "user", "body": user_input})
|
||||||
|
|
||||||
|
messages.append({"author": "user", "body": "Read the message and provid a single letter response."})
|
||||||
|
messages.append({"author": "user", "body": pairings})
|
||||||
|
|
||||||
|
|
||||||
|
f_body = formatter.format(context, messages, for_completion=True)
|
||||||
|
f_resp = await get_response_wrapper(f_body)
|
||||||
|
|
||||||
|
return f_resp[0].lower()
|
||||||
|
|
||||||
# When the Discord bot starts up successfully:
|
# When the Discord bot starts up successfully:
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
@ -182,6 +207,8 @@ async def on_ready():
|
|||||||
@client.event
|
@client.event
|
||||||
async def on_message(msg):
|
async def on_message(msg):
|
||||||
global praise
|
global praise
|
||||||
|
global mood_happiness
|
||||||
|
global mood_energy
|
||||||
|
|
||||||
if msg.author.id == client.user.id:
|
if msg.author.id == client.user.id:
|
||||||
return
|
return
|
||||||
@ -294,6 +321,71 @@ async def on_message(msg):
|
|||||||
if chl.topic is not None:
|
if chl.topic is not None:
|
||||||
context = chl.topic
|
context = chl.topic
|
||||||
|
|
||||||
|
if re.search(r"\{\{mood\}\}", context):
|
||||||
|
msg_nature = await get_message_nature(
|
||||||
|
msg.content,
|
||||||
|
"N: The message is neutral. "
|
||||||
|
"A: The message is apologetic towards you. "
|
||||||
|
"S: The message is slightly insulting towards you. "
|
||||||
|
"I: The message is very insulting towards you. "
|
||||||
|
"C: The message is a compliment towards you. "
|
||||||
|
"Q: The message is a technical question for you. "
|
||||||
|
"P: The message is a personal inquiry for you. "
|
||||||
|
"J: The message is a joke or funny. "
|
||||||
|
)
|
||||||
|
|
||||||
|
match msg_nature:
|
||||||
|
case "a":
|
||||||
|
if mood_happiness > 0: mood_happiness = mood_happiness - 1
|
||||||
|
if mood_happiness < 0: mood_happiness = mood_happiness + 1
|
||||||
|
await msg.add_reaction("🙏")
|
||||||
|
|
||||||
|
case "s":
|
||||||
|
mood_happiness = mood_happiness - 1
|
||||||
|
mood_energy = mood_energy - 1
|
||||||
|
await msg.add_reaction("😠")
|
||||||
|
|
||||||
|
case "i":
|
||||||
|
mood_happiness = -5
|
||||||
|
mood_energy = -3
|
||||||
|
await msg.add_reaction("😡")
|
||||||
|
|
||||||
|
case "c":
|
||||||
|
mood_happiness = mood_happiness + 3
|
||||||
|
mood_energy = mood_energy + 3
|
||||||
|
await msg.add_reaction("❤️")
|
||||||
|
|
||||||
|
case "q":
|
||||||
|
mood_energy = mood_energy - 3
|
||||||
|
await msg.add_reaction("🤔")
|
||||||
|
|
||||||
|
case "j":
|
||||||
|
if mood_happiness < 3: mood_happiness = mood_happiness + 1
|
||||||
|
if mood_energy < 3: mood_energy = mood_energy + 1
|
||||||
|
await msg.add_reaction("💀")
|
||||||
|
|
||||||
|
if mood_happiness < -5: mood_happiness = -5;
|
||||||
|
if mood_energy < -5: mood_energy = -5;
|
||||||
|
if mood_happiness > 5: mood_happiness = 5;
|
||||||
|
if mood_energy > 5: mood_energy = 5;
|
||||||
|
|
||||||
|
mood_text = "Mood:\n"
|
||||||
|
|
||||||
|
if mood_happiness == -5: mood_text = f"{mood_text}* Unapologetic, resenting, angry, full of hate\n"
|
||||||
|
if mood_happiness in [-4, -3, -2]: mood_text = f"{mood_text}* Skeptical, unimpressed\n"
|
||||||
|
if mood_happiness in [-1, 0, 1]: mood_text = f"{mood_text}* Emotionally neutral, unbiased\n"
|
||||||
|
if mood_happiness in [2, 3, 4]: mood_text = f"{mood_text}* Positive in nature\n"
|
||||||
|
if mood_happiness == 5: mood_text = f"{mood_text}* Extremely happy and ecstatic\n"
|
||||||
|
|
||||||
|
if mood_energy == -5: mood_text = f"{mood_text}* Low effort, one word replies\n"
|
||||||
|
if mood_energy in [-4, -3, -2]: mood_text = f"{mood_text}* Very short answers\n"
|
||||||
|
if mood_energy in [-1, 0, 1]: mood_text = f"{mood_text}* Short answers\n"
|
||||||
|
if mood_energy in [2, 3, 4]: mood_text = f"{mood_text}* Short answers\n"
|
||||||
|
if mood_energy == 5: mood_text = f"{mood_text}* Long answers\n"
|
||||||
|
|
||||||
|
mood_text = f"{mood_text}\nMake your answer reflect your mood."
|
||||||
|
context = re.sub(r"\{\{mood\}\}", mood_text, context)
|
||||||
|
|
||||||
print(f"{user_name}: {msg.content}")
|
print(f"{user_name}: {msg.content}")
|
||||||
print(f"{bot_name}: ", end="")
|
print(f"{bot_name}: ", end="")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user