Most of the Admidio event plugins now makes use of the Admidio Python API
This commit also adds the function which enables users to request participants from the bot.
This commit is contained in:
parent
a3a39f8b8f
commit
2b488ee1f8
@ -11,11 +11,18 @@ import hjson
|
||||
import time
|
||||
import sqlite3
|
||||
import threading
|
||||
import importlib
|
||||
import sys
|
||||
import datetime as dt
|
||||
import MySQLdb as mysql
|
||||
|
||||
from matrix_bot_api.mregex_handler import MRegexHandler
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
import admidio_python_api.admidio as admidio
|
||||
import admidio_python_api.group as group
|
||||
|
||||
MESSAGES_DIR = os.path.join(os.path.dirname(__file__), 'messages')
|
||||
DATA_DIR = os.path.join(os.path.dirname(__file__),'../../data/events')
|
||||
CONFIG_LOCATION = os.path.join(os.path.dirname(__file__), 'config.hjson')
|
||||
@ -37,6 +44,13 @@ class Plugin:
|
||||
with open(MESSAGES_LOCATION) as hjson_data:
|
||||
self.messages = hjson.load(hjson_data)
|
||||
|
||||
self.adm = admidio.Admidio(
|
||||
self.config['database_credentials']['host'],
|
||||
self.config['database_credentials']['username'],
|
||||
self.config['database_credentials']['password'],
|
||||
self.config['database_credentials']['database'],
|
||||
self.config['database_credentials']['adm_prefix'])
|
||||
|
||||
# Define sensitivity
|
||||
self.handler = []
|
||||
|
||||
@ -64,7 +78,6 @@ class Plugin:
|
||||
database = self.config['database_credentials']['database'],
|
||||
host = self.config['database_credentials']['host'])
|
||||
|
||||
|
||||
def check_new_event_thread(self):
|
||||
while not self.bot.cancel:
|
||||
self.check_new_event()
|
||||
@ -150,7 +163,8 @@ class Plugin:
|
||||
if room.display_name in mapping[1]:
|
||||
room.send_html(
|
||||
self.messages["new_event"].format(
|
||||
row[3].strftime("%d-%m-%Y om %H:%M"),
|
||||
row[3].strftime("%d-%m-%Y"),
|
||||
row[3].strftime("%H:%M"),
|
||||
row[2],
|
||||
view_link,
|
||||
attend_link,
|
||||
@ -183,42 +197,33 @@ class Plugin:
|
||||
room.send_text(self.messages['list_event_num_err'])
|
||||
number_events = 10
|
||||
|
||||
datetime_now = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
mysql_db = self.connect_database()
|
||||
mysql_cursor = mysql_db.cursor()
|
||||
|
||||
select_sql = f"""SELECT dat_id, dat_cat_id,
|
||||
dat_headline, dat_begin, dat_end
|
||||
FROM adm_dates
|
||||
WHERE dat_begin >'{datetime_now}'
|
||||
ORDER BY dat_begin
|
||||
LIMIT {number_events}"""
|
||||
|
||||
mysql_cursor.execute(select_sql)
|
||||
|
||||
# Fetch events
|
||||
results = mysql_cursor.fetchall()
|
||||
|
||||
# Set header
|
||||
html_message = self.messages['list_events_head'].format(number_events)
|
||||
|
||||
# Loop through fetched events
|
||||
html_message += "<br /><ul>"
|
||||
for row in results:
|
||||
base_date_url = "{}{}".format(
|
||||
self.config['base_url_adm'],
|
||||
"/adm_program/modules/dates/")
|
||||
|
||||
function_link = "{}dates_function.php?mode={}&dat_id={}&"
|
||||
|
||||
attend_link = function_link.format(base_date_url, '3', row[0])
|
||||
now = dt.datetime.now()
|
||||
events = (x for (k,x) in self.adm.events.items() if x.start_time > now)
|
||||
|
||||
# Set header
|
||||
html_message = self.messages['list_events_head'].format(number_events)
|
||||
|
||||
# Loop through fetched events
|
||||
html_message += "<br /><ul>"
|
||||
for (i, event) in enumerate(events):
|
||||
if (i >= number_events):
|
||||
break;
|
||||
|
||||
attend_link = function_link.format(base_date_url, '3', event.id)
|
||||
|
||||
html_message += "<li>"
|
||||
html_message += self.messages['list_event_item'].format(
|
||||
row[3].strftime("%d-%m-%Y om %H:%M"),
|
||||
row[2],
|
||||
row[0],
|
||||
event.start_time.strftime("%d-%m-%Y"),
|
||||
event.start_time.strftime("%H:%M"),
|
||||
event.name,
|
||||
event.id,
|
||||
attend_link)
|
||||
html_message += "</li>"
|
||||
|
||||
@ -227,9 +232,6 @@ class Plugin:
|
||||
# Send message
|
||||
room.send_html(html_message)
|
||||
|
||||
# Close DB connection
|
||||
mysql_db.close()
|
||||
|
||||
def info_callback(self, room, event):
|
||||
id_event = False
|
||||
|
||||
@ -244,39 +246,89 @@ class Plugin:
|
||||
room.send_html(self.messages['info_event_id_err'])
|
||||
return
|
||||
|
||||
mysql_db = self.connect_database()
|
||||
mysql_cursor = mysql_db.cursor()
|
||||
|
||||
select_sql = f"""SELECT dat_id, dat_headline, dat_description,
|
||||
dat_begin, dat_end
|
||||
FROM adm_dates
|
||||
WHERE dat_id = {id_event}"""
|
||||
|
||||
mysql_cursor.execute(select_sql)
|
||||
|
||||
# Fetch events
|
||||
row = mysql_cursor.fetchall()
|
||||
|
||||
try:
|
||||
date_url = "{}{}{}".format(
|
||||
self.config['base_url_adm'],
|
||||
"/adm_program/modules/dates/dates.php?id=",
|
||||
row[0][0])
|
||||
self.adm.events[id_event].id)
|
||||
|
||||
html_message = self.messages['info_event'].format(
|
||||
date_url,
|
||||
row[0][1],
|
||||
row[0][3].strftime("%d-%m-%Y om %H:%M"),
|
||||
row[0][4].strftime("%d-%m-%Y om %H:%M"),
|
||||
row[0][2])
|
||||
self.adm.events[id_event].name,
|
||||
self.adm.events[id_event].start_time.strftime("%d-%m-%Y"),
|
||||
self.adm.events[id_event].start_time.strftime("%H:%M"),
|
||||
self.adm.events[id_event].end_time.strftime("%d-%m-%Y"),
|
||||
self.adm.events[id_event].end_time.strftime("%H:%M"),
|
||||
self.adm.events[id_event].description)
|
||||
|
||||
# Send message
|
||||
room.send_html(html_message)
|
||||
|
||||
# Close DB connection
|
||||
mysql_db.close()
|
||||
except KeyError:
|
||||
room.send_html(self.messages['unknown_event'])
|
||||
|
||||
|
||||
def participants_callback(self, room, event):
|
||||
room.send_text("Deelnemers")
|
||||
id_event = False
|
||||
|
||||
for word in event['content']['body'].split():
|
||||
try:
|
||||
id_event = int(word)
|
||||
break
|
||||
except:
|
||||
pass
|
||||
|
||||
if not id_event or id_event < 0:
|
||||
room.send_html(self.messages['info_event_id_err'])
|
||||
return
|
||||
|
||||
# Set header
|
||||
html_message = self.messages['event_participants_head'].format(
|
||||
len(self.adm.events[id_event].getAllAttend()),
|
||||
self.adm.events[id_event].number_of_guests,
|
||||
self.adm.events[id_event].name)
|
||||
|
||||
# Attend
|
||||
html_message += "<br />"
|
||||
html_message += self.messages['event_participants_attend'];
|
||||
|
||||
# Loop through fetched participants
|
||||
html_message += "<ul>"
|
||||
|
||||
for member in self.adm.events[id_event].getAllAttend():
|
||||
html_message += "<li>"
|
||||
html_message += member[1].username
|
||||
html_message += "</li>"
|
||||
|
||||
html_message += "</ul>"
|
||||
|
||||
# Maybe
|
||||
html_message += self.messages['event_participants_maybe'];
|
||||
|
||||
# Loop through fetched participants
|
||||
html_message += "<ul>"
|
||||
|
||||
for member in self.adm.events[id_event].getAllMaybe():
|
||||
html_message += "<li>"
|
||||
html_message += member[1].username
|
||||
html_message += "</li>"
|
||||
|
||||
html_message += "</ul>"
|
||||
|
||||
# Not attend
|
||||
html_message += self.messages['event_participants_not_attend'];
|
||||
|
||||
# Loop through fetched participants
|
||||
html_message += "<ul>"
|
||||
|
||||
for member in self.adm.events[id_event].getAllNotAttend():
|
||||
html_message += "<li>"
|
||||
html_message += member[1].username
|
||||
html_message += "</li>"
|
||||
|
||||
html_message += "</ul>"
|
||||
|
||||
room.send_html(html_message)
|
||||
|
||||
def chat_callback(self, room, event):
|
||||
room.send_text("Chat")
|
||||
|
@ -3,7 +3,8 @@
|
||||
"username": "",
|
||||
"password": "",
|
||||
"database": "",
|
||||
"host": ""
|
||||
"host": "",
|
||||
"adm_prefix": "adm"
|
||||
},
|
||||
"cat_id_room_mapping": [
|
||||
[[], ""],
|
||||
|
@ -2,7 +2,7 @@
|
||||
"new_event":
|
||||
'''
|
||||
<strong>@room er is zojuist een nieuw evenement aangemaakt!
|
||||
Op {} zal "{}" plaatsvinden.</strong>
|
||||
Op {} om {} zal "{}" plaatsvinden.</strong>
|
||||
|
||||
<br /><br />
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
"list_event_item":
|
||||
'''
|
||||
{}: <strong>{}</strong> (ID: {}, <a href='{}'>aanmelden</a>)
|
||||
{} om {}: <strong>{}</strong> (ID: {}, <a href='{}'>aanmelden</a>)
|
||||
''',
|
||||
|
||||
"list_event_num_err":
|
||||
@ -44,11 +44,38 @@
|
||||
"info_event":
|
||||
'''
|
||||
Je hebt informatie opgevraagd over het evenement: "<a href="{}">{}</a>".
|
||||
Het evenement begint op {} en eindigt op {}. De maker van het
|
||||
Het evenement begint op {} om {} en eindigt op {} om {}. De maker van het
|
||||
evenement heeft deze beschrijving toegevoegd:
|
||||
|
||||
<br /><br />
|
||||
|
||||
<blockquote>{}</blockquote>
|
||||
''',
|
||||
|
||||
"unknown_event":
|
||||
'''
|
||||
Sorry, ik ken helaas geen evenement met dit ID. Probeer het alsjeblieft met
|
||||
een ander ID.
|
||||
''',
|
||||
|
||||
"event_participants_head":
|
||||
'''
|
||||
Er nemen {} leden en {} gasten deel aan "{}". De aangemelde leden zijn:
|
||||
''',
|
||||
|
||||
"event_participants_attend":
|
||||
'''
|
||||
<h5>Aanwezig:</h5>
|
||||
''',
|
||||
|
||||
"event_participants_maybe":
|
||||
'''
|
||||
<h5>Maybe:</h5>
|
||||
''',
|
||||
|
||||
"event_participants_not_attend":
|
||||
'''
|
||||
<h5>Afwezig:</h5>
|
||||
''',
|
||||
|
||||
}
|
||||
|
@ -1 +1,2 @@
|
||||
mysqlclient
|
||||
python-dateutil
|
||||
|
Loading…
Reference in New Issue
Block a user