2024-02-06 01:00:41 +00:00
|
|
|
import ollama
|
2024-02-06 01:21:53 +00:00
|
|
|
import scraper_functions as sf
|
2024-02-08 00:57:36 +00:00
|
|
|
import random
|
|
|
|
from frontends import FRONTENDS
|
2024-02-06 01:04:47 +00:00
|
|
|
|
2024-02-05 23:40:23 +00:00
|
|
|
def processmsg(msg, rcpt):
|
2024-02-08 00:57:36 +00:00
|
|
|
if msg.startswith("!"):
|
2024-02-06 20:05:02 +00:00
|
|
|
return command(msg, "")
|
2024-02-06 01:13:36 +00:00
|
|
|
elif "good bot" in msg:
|
|
|
|
return "^_^"
|
2024-02-08 00:57:36 +00:00
|
|
|
for big_tech_site in FRONTENDS:
|
|
|
|
if big_tech_site in msg:
|
|
|
|
return "libre link: " + msg.replace(big_tech_site, random.choice(FRONTENDS[big_tech_site]))
|
2024-02-06 00:03:54 +00:00
|
|
|
|
|
|
|
def command(msg, rcpt):
|
|
|
|
if msg.startswith("!help"):
|
2024-02-06 01:07:47 +00:00
|
|
|
response = "chatbot commands:" + "\n"
|
|
|
|
response += "!help Show this help page" + "\n"
|
2024-02-06 01:47:01 +00:00
|
|
|
response += "!ai [message] Ask llama2" + "\n"
|
2024-02-06 21:18:44 +00:00
|
|
|
response += "!wiki [message] Ask wiki\n"
|
|
|
|
response += "!tasks Show active tasks from the taskmanager\n"
|
2024-02-07 22:47:36 +00:00
|
|
|
response += "!vreme [city] | !prognoza [city] | !weather [city] Show weather for [city]\n"
|
2024-02-06 01:05:31 +00:00
|
|
|
return response
|
2024-02-06 01:00:41 +00:00
|
|
|
elif msg.startswith("!ai"):
|
|
|
|
client = ollama.Client(host='https://ollama.krov.dmz.rs')
|
|
|
|
response = client.chat(model='llama2-uncensored:latest', messages=[{'role':'user','content':f'{msg[4:]}'}])
|
|
|
|
return(response['message']['content'])
|
2024-02-06 19:48:08 +00:00
|
|
|
elif msg.startswith("!wiki"):
|
2024-02-06 19:51:31 +00:00
|
|
|
cmd, query = msg.split(" ", 1)
|
|
|
|
return sf.query_external_website("https://en.wikipedia.org", "/wiki/" + query)
|
2024-02-06 20:17:49 +00:00
|
|
|
elif msg.startswith("!tasks"):
|
2024-02-06 20:24:04 +00:00
|
|
|
content = sf.getDmzTasks("https://todo.dmz.rs/")
|
2024-02-06 20:17:49 +00:00
|
|
|
return content
|
2024-02-07 22:47:36 +00:00
|
|
|
elif msg.startswith("!vreme") or msg.startswith("!prognoza") or msg.startswith("!weather"):
|
2024-03-04 10:28:32 +00:00
|
|
|
commandsplit = msg.split(" ", 1)
|
2024-03-04 10:32:37 +00:00
|
|
|
if len(commandsplit) == 1:
|
2024-03-04 10:28:32 +00:00
|
|
|
return sf.get_weather("Beograd")
|
|
|
|
else:
|
|
|
|
query = commandsplit[1]
|
|
|
|
return sf.get_weather(query)
|