Added info event feature

The bot is now able to return information about a certain event to a room.
This commit is contained in:
Dennis Potter 2019-01-27 17:58:24 +01:00
parent 09dd17c9f2
commit 06868d67ce
Signed by: Dennis
GPG Key ID: 186A8AD440942BAF
2 changed files with 70 additions and 10 deletions

View File

@ -150,8 +150,7 @@ class Plugin:
if room.display_name in mapping[1]:
room.send_html(
self.messages["new_event"].format(
row[3].strftime("%d-%m-%Y"),
row[3].strftime("%H:%M"),
row[3].strftime("%d-%m-%Y om %H:%M"),
row[2],
view_link,
attend_link,
@ -190,7 +189,7 @@ class Plugin:
mysql_cursor = mysql_db.cursor()
select_sql = f"""SELECT dat_id, dat_cat_id,
dat_headline, dat_begin, dat_end
dat_headline, dat_begin, dat_end
FROM adm_dates
WHERE dat_begin >'{datetime_now}'
ORDER BY dat_begin
@ -217,9 +216,9 @@ class Plugin:
html_message += "<li>"
html_message += self.messages['list_event_item'].format(
row[3].strftime("%d-%m-%Y"),
row[3].strftime("%H:%M"),
row[3].strftime("%d-%m-%Y om %H:%M"),
row[2],
row[0],
attend_link)
html_message += "</li>"
@ -232,14 +231,56 @@ class Plugin:
mysql_db.close()
def info_callback(self, room, event):
room.send_text("Info")
id_event = False
def chat_callback(self, room, event):
room.send_text("Chat")
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
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()
date_url = "{}{}{}".format(
self.config['base_url_adm'],
"/adm_program/modules/dates/dates.php?id=",
row[0][0])
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])
# Send message
room.send_html(html_message)
# Close DB connection
mysql_db.close()
def participants_callback(self, room, event):
room.send_text("Deelnemers")
def chat_callback(self, room, event):
room.send_text("Chat")
def help(self):
return open(HELP_LOCATION, mode="r").read()

View File

@ -2,7 +2,7 @@
"new_event":
'''
<strong>@room er is zojuist een nieuw evenement aangemaakt!
Op {} om {} zal "{}" plaatsvinden.</strong>
Op {} zal "{}" plaatsvinden.</strong>
<br /><br />
@ -24,12 +24,31 @@
"list_event_item":
'''
{} om {}: <strong>{}</strong> (<a href='{}'>aanmelden</a>)
{}: <strong>{}</strong> (ID: {}, <a href='{}'>aanmelden</a>)
''',
"list_event_num_err":
'''
Let op: alleen de getallen [1,100] zijn toegestaan!
Ik pak de standaard waarde 10.
''',
"info_event_id_err":
'''
Let op: alleen natuurlijke getallen (0, 1, 2, 3, 4, ... voor de mensen
die HöMa 1 nog niet gehaald hebben 😉) zijn toegestaan. Vraag de lijst
van evenementen op, om het identificatienummer van het evenement dat
je zoekt te vinden.
''',
"info_event":
'''
Je hebt informatie opgevraagd over het evenement: "<a href="{}">{}</a>".
Het evenement begint op {} en eindigt op {}. De maker van het
evenement heeft deze beschrijving toegevoegd:
<br /><br />
<blockquote>{}</blockquote>
'''
}