diff --git a/asmodee.ini.sample b/asmodee.ini.sample index 9305472..601f522 100644 --- a/asmodee.ini.sample +++ b/asmodee.ini.sample @@ -5,8 +5,8 @@ server = https://instance.tld admin = @mxid:intance.tld [MOD] -# liste = roll,quote,biere,stats,liste,horloge,carte,card,cristal,welcome,salut,jdr,gens,va,salon,kick,mails,titre,invidious -liste = roll,quote,biere,stats,liste,horloge,carte,card,cristal,welcome,salut,jdr,gens,va,salon,kick,mails,titre,invidious +# liste = roll,quote,biere,stats,liste,horloge,carte,card,cristal,welcome,salut,jdr,gens,va,salon,kick,mails,titre,invidious,ecowatt,commune +liste = roll,quote,biere,stats,liste,horloge,carte,card,cristal,welcome,salut,jdr,gens,va,salon,kick,mails,titre,invidious,ecowatt,commune [MAIL] malt = 0 @@ -18,4 +18,3 @@ mport = port [RTE] client_id = id client_secret = secret -call_url = https://digital.iservices.rte-france.com/open_api/ecowatt/v4/signals diff --git a/asmodee.py b/asmodee.py index 632f747..6584f18 100755 --- a/asmodee.py +++ b/asmodee.py @@ -28,6 +28,7 @@ USERNAME = "" oauth = None #Appels RTE #ecowatt_url = 'https://digital.iservices.rte-france.com/open_api/ecowatt/v4/sandbox/signals' ecowatt_url = 'https://digital.iservices.rte-france.com/open_api/ecowatt/v4/signals' +commune_url = 'https://geo.api.gouv.fr/communes?nom=&fields=codesPostaux,population&format=json' wattobj = None # Listes et dictionnaires @@ -1664,6 +1665,35 @@ async def ecowatt(room, message): alerte = getNiveau(jour["dvalue"]) mess = mess + "La météo RTE du " + jour["jour"][0:10] + " est de niveau " + alerte + " (" + jour["message"] + ")\n" await msg(room, mess, sender) + +async def commune(room, message): + global modules + try: + rmod = modules[room.room_id, 'commune'] + except: + modules[room.room_id, 'commune'] = False + if (modules[room.room_id, 'commune']): + args = getMessage(message).split() + sender = getUser(message) + args.pop(0) + mess = "" + if (len(args) > 0): + ville = " ".join(args) + cette_commune = commune_url.replace("", ville) + result = oauth.get(cette_commune) + villes = json.loads(result.text) + if (len(villes) > 0): + try: + cite = villes[0] + code = cite["codesPostaux"][0] + pop = cite["population"] + await msg(room, ville + ". CP : " + code + ". Population : " + str(pop), sender) + except: + await msg(room, str(villes), sender) + else: + await msg(room, "Commune non trouvée", sender) + else: + await msg(room, "!commune \n\nRetrouvez Asmodee sur https://git.ombreport.info/nemesis/asmodee_matrix" await msg(salon,message,sender, False) +@bot.listener.on_message_event +async def callCommune(room, message): + match = botlib.MessageMatch(room, message, bot, PREFIX) + if match.is_not_from_this_bot() and match.prefix() and match.command("commune"): + await commune(room, message) + @bot.listener.on_message_event async def callEcowatt(room, message): match = botlib.MessageMatch(room, message, bot, PREFIX) @@ -1909,7 +1945,7 @@ def main(): USERNAME = "" # Bot's username PASSWORD = "" # Bot's password SERVER = "" # Matrix server URL - mods = ["roll", "quote", "biere", "stats", "liste", "horloge", "carte", "card", "cristal", "welcome", "salut", "jdr", "gens", "va", "salon", "kick", "mails", "titre", "invididious", "ecowatt"] + mods = ["roll", "quote", "biere", "stats", "liste", "horloge", "carte", "card", "cristal", "welcome", "salut", "jdr", "gens", "va", "salon", "kick", "mails", "titre", "invididious", "ecowatt", "commune"] global admins if ('AUTH' in config): USERNAME = config['AUTH']['username'] # Bot's username