Commit 29a8b29f authored by Otthorn's avatar Otthorn 🤔

deleted useless stuff

parent 8c8e3a0e
import random
from matrix_bot_api.matrix_bot_api import MatrixBotAPI
from matrix_bot_api.mregex_handler import MRegexHandler
from matrix_bot_api.mcommand_handler import MCommandHandler
from giphy_api import gif_search
from parse_env import parse_env
import random
from matrix_user_id import format_arguments, get_id_from_link, get_link_from_id
import configparser
import citations
# Parse the global variables from the env
dico_env = parse_env("matrix.env")
# Load the quote database
quote_dico = citations.load_db()
USERNAME = dico_env['USERNAME'] # Bot's username
PASSWORD = dico_env['PASSWORD'] # Bot's password
SERVER = dico_env['SERVER'] # Matrix server URL
# define the bot object
# define the callbacks
def hi_callback(room, event):
......@@ -66,51 +52,23 @@ def help_callback(room, event):
<li><em>!help</em> <strong>X</strong> permet de trouver de l'aide sur <strong>X</strong>;\
<li><em>!d<strong>N</strong></em> donne le résultat d'un dé à <strong>N</strong> faces;</li>\n\
<li><em>!echo</em> <strong>X</strong> renvoie un message contenant <strong>X</strong>;</li>\n\
<li><em>!weather</em> <strong>L</strong> renvoie la météo pour l'emplacement <strong>L</strong>;</li>\n\
<li><em>!gif</em> <strong>X</strong> renvoie un gif correspondant à la recherche <strong>X</strong>.</li>\n</ul>\n")
<li><em>!echo</em> <strong>X</strong> renvoie un message contenant <strong>X</strong>;</li>\n</ul>\n")
elif args[1] in ("d", "dice", "die", "dés", "dé", "dN", "!dN"):
room.send_html("<em>!d<strong>N</strong></em> est une commande pour \
lancer un dé à <strong>N</strong> face(s). <strong>N</strong> entre 1 et 1000.\
<br /><em>Exemple</em> : <code>!d20</code> pour lancer un dé à 20 faces.")
elif args[1] in ("gif", "!gif"):
room.send_html("<em>!gif</em> <strong>X</strong> permet d'afficher un \
gif correspondant à la recherche <strong>X</strong>.<br /><em>Exemple</em> : \
<code>!gif suhsi</code> renvera un gif avec des suhsi !")
elif args[1] in ("echo", "!echo"):
room.send_html("<em>!echo</em> <strong>X</strong> renvoie un message \
contenant <strong>X</strong>.<br /><em>Exemple</em> : <code>!echo Med</code> \
renverra le message <code>Med</code>.")
elif args[1] in ("meteo", "weather", "!weather"):
room.send_html("<em>!weather</em> <strong>L</strong> renvoie la\
météo pour l'emplacement <strong>L</strong>. On peut spécifier soit \
<code>ville</code> soit <code>ville, pays</code>.<br /><em>Exemple</em>\
: <code>!weather Cachan</code> ou bien <code>!weather newcastle, gb</code>.")
def gif_callback(room, event):
args = event['content']['body'].split()
query = " ".join(args[1:])
print("GIF called with query={} in room={}".format(query, room.display_name))
data, mime = gif_search(query)
mxc_url = bot.client.upload(data, mime)
room.send_image(mxc_url, query, mimetype=mime)
def quote_callback(room, event):
args = event['content']['body'].split()
......@@ -160,6 +118,15 @@ def list_quote_callback(room, event):
def main():
# Load the configuration
config = configparser.ConfigParser()"config.ini")
username = config.get("Matrix", "username")
password = config.get("Matrix", "password")
server = config.get("Matrix", "server")
# Start bot
bot = MatrixBotAPI(username, password, server)
# Add a regex handler waiting for the word Hi
hi_handler = MRegexHandler("Bonjour|Bonsoir|bonjour|bonsoir|Salut|salut", hi_callback)
......@@ -176,9 +143,6 @@ def main():
help_handler = MCommandHandler("help", help_callback)
gif_handler = MCommandHandler("gif", gif_callback)
quote_handler = MCommandHandler("citation", quote_callback)
......@@ -187,6 +151,7 @@ def main():
# Start polling
print("med_maid started")
# Infinitely read stdin to stall main thread while the bot runs in other threads
while True:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment