Commit 28d1a4e0 authored by otthorn's avatar otthorn

changed food and gif

parent 6028519c
......@@ -39,5 +39,6 @@ def main():
while True:
input()
if __name__ == "__main__":
main()
# -*- coding: utf-8 -*-
import better_random
import json
from urllib.request import urlopen
......@@ -13,7 +15,8 @@ def gif_search(query, query_type, api_key, limit):
query = quote_plus(query) # make the query browser compliant
data = json.loads(urlopen("http://api.giphy.com/v1/"+query_type+"/search?q="+query+"&api_key="+api_key+"&limit="+limit).read())
json_obj = urlopen("http://api.giphy.com/v1/"+query_type+"/search?q=" + query + "&api_key=" + api_key + "&limit=" + limit).read()
data = json.loads(json_obj.decode('utf-8'))
maximum_id = len(data['data']) - 1
......@@ -49,6 +52,12 @@ class MyMatrixBotAPI(MatrixBotAPI):
args = event['content']['body'].split()
query = " ".join(args[1:])
sender = event['sender']
if "_discord_" in sender:
print("message envoyé par qqun de discord !")
return
print("[{}] {} called with query={} in room={}".format(log_time(), query_type, query, room.display_name))
result = gif_search(query, "gifs", self.api_key, self.limit)
......@@ -84,25 +93,36 @@ def main():
api_key = config.get("Gif", "api_key")
limit = config.get("Gif", "limit")
# Start bot
bot = MyMatrixBotAPI(username, password, server, api_key, limit)
# Created handler
gif_handler = MCommandHandler("gif", bot.gif_callback)
bot.add_handler(gif_handler)
try:
# Start bot
bot = MyMatrixBotAPI(username, password, server, api_key, limit)
sticker_handler = MCommandHandler("sticker", bot.sticker_callback)
bot.add_handler(sticker_handler)
reaction_handler = MCommandHandler("reaction", bot.reaction_callback)
bot.add_handler(reaction_handler)
# Created handler
gif_handler = MCommandHandler("gif", bot.gif_callback)
bot.add_handler(gif_handler)
# Start polling
bot.start_polling()
print("gif_bot started")
while True:
input()
sticker_handler = MCommandHandler("sticker", bot.sticker_callback)
bot.add_handler(sticker_handler)
reaction_handler = MCommandHandler("reaction", bot.reaction_callback)
bot.add_handler(reaction_handler)
# Start polling
bot.start_polling()
print("gif_bot started")
while True:
input()
except:
print("Error in start...while loop")
pass
if __name__ == "__main__":
main()
try:
main()
except:
print("Error in main()")
pass
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