main
Gabriel 2 years ago
parent 2826163493
commit 6c71c30454

@ -26,5 +26,11 @@ You may want to set data.json as a volume to be able to make changes on the fly
![matrix room screenshot](screenshots/example2.png)
## Features in the works
* Alerts
* Dynamic configuration
* Meeting requests
* Configurable API calls

@ -1,18 +1,19 @@
import random
import features
jokes = [
["Testing","Testing you!"],
["singing pokemon","Jiggalypuff! 🎙️"]
]
#jokes = []
def handle_command(state,message):
def handle_command(state,sender,message):
for command in commands:
if message.find(command)==0:
result = commands[command](state,message)
result = commands[command](state,message,sender)
return result
if len(state) > 0:
try:
result = commands[state[0]](state,message)
result = commands[state[0]](state,message,sender)
return result
except Exception as e:
return {
@ -39,13 +40,13 @@ def handle_command(state,message):
bot: Nice one! -> bot saves knock-knock joke
"""
def nevermind(state,message):
def nevermind(state,message,sender):
return {
"response":"starting over.",
"state":[]
}
def knock_knock(state,message):
def knock_knock(state,message,sender):
#return {response:"",state:""}
try:
if state[0] != "knock knock":
@ -93,7 +94,7 @@ def knock_knock(state,message):
bot:
"""
def joke(state,message):
def joke(state,message,sender):
if len(jokes) == 0:
return {
"response":"I don't know any jokes...",
@ -134,8 +135,16 @@ def joke(state,message):
"response":None,
"state":[]
}
"""
"""
def appointments():
return {
"response":None,
state:[]
}
commands = {
"nevermind":nevermind,
"knock knock":knock_knock,
@ -144,7 +153,6 @@ commands = {
if __name__ == '__main__':
msg = ""
while msg != "exit":

@ -23,5 +23,7 @@
"footer": "Brought to you by Nerve\nSee the [code](https://codeberg.org/gabe/Nerve)"
},
"users": {}
"users": {},
"admins": [],
"meetings": []
}

@ -0,0 +1,82 @@
import json
import requests
"""
Features
This is the main API for executing functions with data
"""
class API:
def __init__(self):
with open('data.json') as f:
self.data = json.loads(f.read())
# Only refresh data when a change is made
def save(self):
with open('data.json','w') as f:
f.write(json.dumps(self.data,indent=2))
return True
return False
#Administration
def is_admin(self,handle):
#return bool
pass
def add_admin(self,handle):
#return bool
if self.is_admin(handle):
return True
else:
self.data["admins"].append(handle)
self.save()
return True
def remove_admin(self,handle):
#return bool
if self.is_admin(handle):
i = self.data["admins"].index(handle)
self.data["admins"].pop(i)
self.save()
return True
else:
return True
#FAQ
def get_header(self):
return self.data["faq"]["header"]
def set_header(self,hdr):
#return bool
self.data["faq"]["header"] = hdr
self.save()
return True
def get_questions(self):
#return questions
return self.data["faq"]["questions"]
def add_question(self,qtn):
#return bool
self.data["faq"]["questions"].append(qtn)
self.save()
return True
def remove_question(self,qtn_i):
#return bool
self.data["faq"]["questions"].pop(qtn_i)
self.save()
return True
def update_question(self,qtn_i,qtn):
#return bool
self.data["faq"]["questions"][qtn_i]=qtn
return True
#Meetings
def get_meetings():
pass
def request_meeting():
pass
def accept_meeting():
pass
if __name__ == '__main__':
storeAPI = API()
print("Storage loaded.\n",storeAPI.data['username'])

@ -3,6 +3,8 @@ import nio
import simplematrixbotlib as botlib
import commands
#TODO move state functionality entirely to features.py
data = json.loads(open('data.json').read())
dfaq = data["faq"]
userstate = data['users']
@ -34,7 +36,7 @@ async def faq(room, message):
state = userstate[message.sender]['state']
result = commands.handle_command(state,message.body)
result = commands.handle_command(state,message.sender,message.body)
if result['response']!= None:
state = result['state']
userstate[message.sender]['state'] = result['state']

Loading…
Cancel
Save