generated from Nemesis/Exemple
Compare commits
No commits in common. "7262d190bacc1ce3efe2edd4cebcb0ccdd872fb3" and "d1d1c4ba600b3369f7264c2fd6e4298c8714f7df" have entirely different histories.
7262d190ba
...
d1d1c4ba60
2 changed files with 18 additions and 143 deletions
|
@ -5,8 +5,8 @@ server = https://instance.tld
|
||||||
admin = @mxid:intance.tld
|
admin = @mxid:intance.tld
|
||||||
|
|
||||||
[MOD]
|
[MOD]
|
||||||
# liste = roll,quote,biere,stats,liste,horloge,carte,card,cristal,welcome,salut,jdr,gens,va,salon,kick,mails,titre,invidious,ecowatt,commune,eau
|
# 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,eau
|
liste = roll,quote,biere,stats,liste,horloge,carte,card,cristal,welcome,salut,jdr,gens,va,salon,kick,mails,titre,invidious
|
||||||
|
|
||||||
[MAIL]
|
[MAIL]
|
||||||
malt = 0
|
malt = 0
|
||||||
|
@ -18,3 +18,4 @@ mport = port
|
||||||
[RTE]
|
[RTE]
|
||||||
client_id = id
|
client_id = id
|
||||||
client_secret = secret
|
client_secret = secret
|
||||||
|
call_url = https://digital.iservices.rte-france.com/open_api/ecowatt/v4/signals
|
||||||
|
|
156
asmodee.py
156
asmodee.py
|
@ -25,14 +25,9 @@ import json
|
||||||
bot = None
|
bot = None
|
||||||
PREFIX = '!'
|
PREFIX = '!'
|
||||||
USERNAME = ""
|
USERNAME = ""
|
||||||
RTE_ID = None # Bot's RTE ID
|
oauth = None #Appels RTE
|
||||||
RTE_SECRET = None # Bot's RTE SECRET
|
|
||||||
|
|
||||||
#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/sandbox/signals'
|
||||||
ecowatt_url = 'https://digital.iservices.rte-france.com/open_api/ecowatt/v4/signals'
|
ecowatt_url = 'https://digital.iservices.rte-france.com/open_api/ecowatt/v4/signals'
|
||||||
commune_url = 'https://geo.api.gouv.fr/communes?<TYPE>=<NOM>&fields=nom,code,codesPostaux,population&format=json'
|
|
||||||
eau_url = 'https://hubeau.eaufrance.fr/api/v1/qualite_eau_potable/resultats_dis?<TYPE>=<NOM>&size=20&code_parametre=1301,1302,1312,1313,1305,1335,1339,1340,1350,1433,1377,1338,6276,1295,1382,1383,1388,1387,1392'
|
|
||||||
|
|
||||||
wattobj = None
|
wattobj = None
|
||||||
|
|
||||||
# Listes et dictionnaires
|
# Listes et dictionnaires
|
||||||
|
@ -227,7 +222,7 @@ class Userstats: #Pour garder des stats sur les users
|
||||||
def __init__(self,room,user,nick):
|
def __init__(self,room,user,nick):
|
||||||
self.room = room
|
self.room = room
|
||||||
self.user = user
|
self.user = user
|
||||||
self.nick = nick.strip() if nick and nick != None else ""
|
self.nick = nick.strip()
|
||||||
self.date = 0
|
self.date = 0
|
||||||
self.mess = 0
|
self.mess = 0
|
||||||
self.char = 0
|
self.char = 0
|
||||||
|
@ -697,10 +692,7 @@ def getMessage(message):
|
||||||
|
|
||||||
def getUser(message):
|
def getUser(message):
|
||||||
match = re.search(r"^(@\w+:[^ :]+)", str(message))
|
match = re.search(r"^(@\w+:[^ :]+)", str(message))
|
||||||
if match:
|
return str(match.group())
|
||||||
return str(match.group())
|
|
||||||
else:
|
|
||||||
return "personne"
|
|
||||||
|
|
||||||
def getNick(room, message): # Obtenir le DisplayName à partir du mxid.
|
def getNick(room, message): # Obtenir le DisplayName à partir du mxid.
|
||||||
sender = getUser(message)
|
sender = getUser(message)
|
||||||
|
@ -1262,10 +1254,7 @@ async def bienvenue(room,message): # Affichage d'un message d'accueil aux nouvea
|
||||||
elif (membership == "leave" and prev_member != "leave"):
|
elif (membership == "leave" and prev_member != "leave"):
|
||||||
await msg(room,"Au revoir " + nick + "!",sender)
|
await msg(room,"Au revoir " + nick + "!",sender)
|
||||||
else:
|
else:
|
||||||
try:
|
print("current: " + membership + " prev: " + prev_member)
|
||||||
print("current: " + membership + " prev: " + prev_member)
|
|
||||||
except:
|
|
||||||
print(message)
|
|
||||||
|
|
||||||
async def titre(room, message): # cherche le titre d'une page
|
async def titre(room, message): # cherche le titre d'une page
|
||||||
global modules
|
global modules
|
||||||
|
@ -1638,14 +1627,8 @@ async def ecowatt(room, message):
|
||||||
signals = None
|
signals = None
|
||||||
global wattobj
|
global wattobj
|
||||||
if (wattobj.jour < jn or (wattobj.jour == jn and wattobj.heure + 1 < hn)):
|
if (wattobj.jour < jn or (wattobj.jour == jn and wattobj.heure + 1 < hn)):
|
||||||
try:
|
result = oauth.get(ecowatt_url)
|
||||||
oauth = rte_token()
|
watt = json.loads(result.text)
|
||||||
result = oauth.get(ecowatt_url)
|
|
||||||
watt = json.loads(result.text)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
await msg(room, "Veuillez attendre 15 minutes", sender)
|
|
||||||
return
|
|
||||||
sign = watt["signals"]
|
sign = watt["signals"]
|
||||||
signals = sorted(sign, key=lambda signal: signal["jour"][0:10])
|
signals = sorted(sign, key=lambda signal: signal["jour"][0:10])
|
||||||
wattobj.jour = jn
|
wattobj.jour = jn
|
||||||
|
@ -1681,101 +1664,7 @@ async def ecowatt(room, message):
|
||||||
alerte = getNiveau(jour["dvalue"])
|
alerte = getNiveau(jour["dvalue"])
|
||||||
mess = mess + "La météo RTE du " + jour["jour"][0:10] + " est de niveau " + alerte + " (" + jour["message"] + ")\n"
|
mess = mess + "La météo RTE du " + jour["jour"][0:10] + " est de niveau " + alerte + " (" + jour["message"] + ")\n"
|
||||||
await msg(room, mess, sender)
|
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 = None
|
|
||||||
if (ville.isnumeric()):
|
|
||||||
cette_commune = commune_url.replace("<NOM>", ville).replace("<TYPE>", "codePostal")
|
|
||||||
else:
|
|
||||||
cette_commune = commune_url.replace("<NOM>", ville).replace("<TYPE>", "nom")
|
|
||||||
oauth = rte_token()
|
|
||||||
result = oauth.get(cette_commune)
|
|
||||||
villes = json.loads(result.text)
|
|
||||||
if (len(villes) > 0):
|
|
||||||
try:
|
|
||||||
cites = sorted(villes, key=lambda v: str(v["population"]).zfill(10), reverse=True)
|
|
||||||
cite = cites[0]
|
|
||||||
codePoste = cite["codesPostaux"][0]
|
|
||||||
pop = cite["population"]
|
|
||||||
insee = cite["code"]
|
|
||||||
nom = cite["nom"]
|
|
||||||
await msg(room, nom + ". CP : " + codePoste + ". Code INSEE : " + insee + ". 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 <nom de la commune OU code postal de la commune>", sender)
|
|
||||||
|
|
||||||
async def eau(room, message):
|
|
||||||
global modules
|
|
||||||
try:
|
|
||||||
rmod = modules[room.room_id, 'eau']
|
|
||||||
except:
|
|
||||||
modules[room.room_id, 'eau'] = False
|
|
||||||
if (modules[room.room_id, 'eau']):
|
|
||||||
args = getMessage(message).split()
|
|
||||||
sender = getUser(message)
|
|
||||||
args.pop(0)
|
|
||||||
mess = ""
|
|
||||||
if (len(args) > 0):
|
|
||||||
ville = " ".join(args)
|
|
||||||
cette_commune = None
|
|
||||||
if (ville.isnumeric()):
|
|
||||||
cette_commune = eau_url.replace("<NOM>", ville).replace("<TYPE>", "code_commune")
|
|
||||||
else:
|
|
||||||
cette_commune = eau_url.replace("<NOM>", ville).replace("<TYPE>", "nom_commune")
|
|
||||||
oauth = rte_token()
|
|
||||||
result = oauth.get(cette_commune)
|
|
||||||
eaux = None
|
|
||||||
try:
|
|
||||||
eaux = json.loads(result.text)
|
|
||||||
except:
|
|
||||||
eaux = None
|
|
||||||
if (eaux is not None):
|
|
||||||
if (len(eaux["data"]) > 0):
|
|
||||||
try:
|
|
||||||
f = True
|
|
||||||
comp_msg=""
|
|
||||||
for eau in eaux["data"]:
|
|
||||||
if (f):
|
|
||||||
nom = eau["nom_commune"]
|
|
||||||
distrib = eau["nom_distributeur"]
|
|
||||||
concl = eau["conclusion_conformite_prelevement"]
|
|
||||||
await msg(room, "Prélèvement à " + nom + " réseau " + distrib + ". " + concl, sender)
|
|
||||||
f = False
|
|
||||||
date = eau["date_prelevement"][0:10]
|
|
||||||
res = eau["resultat_alphanumerique"]
|
|
||||||
unite = str(eau["libelle_unite"])
|
|
||||||
if (unite == "SANS OBJET"):
|
|
||||||
unite = ""
|
|
||||||
limite = "(" + str(eau["limite_qualite_parametre"]) + ")"
|
|
||||||
if (limite == "(None)"):
|
|
||||||
limite = ""
|
|
||||||
param = eau["libelle_parametre"] + " " + limite
|
|
||||||
comp_msg = comp_msg + "Résultat du " + date + " : " + res + unite + " / " + param + ".\n"
|
|
||||||
await msg(room, comp_msg, sender)
|
|
||||||
except:
|
|
||||||
await msg(room, str(eaux), sender)
|
|
||||||
else:
|
|
||||||
await msg(room, "Commune non trouvée", sender)
|
|
||||||
else:
|
|
||||||
await msg(room, "Rapport d'eaux non trouvé", sender)
|
|
||||||
else:
|
|
||||||
await msg(room, "!eau <nom de la commune OU code INSEE de la commune>", sender)
|
|
||||||
|
|
||||||
async def help(room, message): # Aide en message privé
|
async def help(room, message): # Aide en message privé
|
||||||
await help_center(room,message,"help",True)
|
await help_center(room,message,"help",True)
|
||||||
|
|
||||||
|
@ -1874,18 +1763,6 @@ async def help_center(room,message,name,private): # Aide sur les commandes dispo
|
||||||
message += "\n- !modo : Gère les modérateurs du salon\n- !module : Gère les modules actifs sur le salon\n\n- Pour plus de details, tapez !" + name + " <commande>\n\nRetrouvez Asmodee sur https://git.ombreport.info/nemesis/asmodee_matrix"
|
message += "\n- !modo : Gère les modérateurs du salon\n- !module : Gère les modules actifs sur le salon\n\n- Pour plus de details, tapez !" + name + " <commande>\n\nRetrouvez Asmodee sur https://git.ombreport.info/nemesis/asmodee_matrix"
|
||||||
await msg(salon,message,sender, False)
|
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 callEau(room, message):
|
|
||||||
match = botlib.MessageMatch(room, message, bot, PREFIX)
|
|
||||||
if match.is_not_from_this_bot() and match.prefix() and match.command("eau"):
|
|
||||||
await eau(room, message)
|
|
||||||
|
|
||||||
@bot.listener.on_message_event
|
@bot.listener.on_message_event
|
||||||
async def callEcowatt(room, message):
|
async def callEcowatt(room, message):
|
||||||
match = botlib.MessageMatch(room, message, bot, PREFIX)
|
match = botlib.MessageMatch(room, message, bot, PREFIX)
|
||||||
|
@ -2026,20 +1903,13 @@ async def callStats(room, message):
|
||||||
if match.is_not_from_this_bot():
|
if match.is_not_from_this_bot():
|
||||||
statistiques(room, message)
|
statistiques(room, message)
|
||||||
|
|
||||||
def rte_token():
|
|
||||||
auth = HTTPBasicAuth(RTE_ID, RTE_SECRET)
|
|
||||||
client = BackendApplicationClient(client_id=RTE_ID)
|
|
||||||
oauth = OAuth2Session(client=client)
|
|
||||||
token = oauth.fetch_token(token_url='https://digital.iservices.rte-france.com/token/oauth/', auth=auth)
|
|
||||||
return(oauth)
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('asmodee.ini')
|
config.read('asmodee.ini')
|
||||||
USERNAME = "" # Bot's username
|
USERNAME = "" # Bot's username
|
||||||
PASSWORD = "" # Bot's password
|
PASSWORD = "" # Bot's password
|
||||||
SERVER = "" # Matrix server URL
|
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", "commune"]
|
mods = ["roll", "quote", "biere", "stats", "liste", "horloge", "carte", "card", "cristal", "welcome", "salut", "jdr", "gens", "va", "salon", "kick", "mails", "titre", "invididious", "ecowatt"]
|
||||||
global admins
|
global admins
|
||||||
if ('AUTH' in config):
|
if ('AUTH' in config):
|
||||||
USERNAME = config['AUTH']['username'] # Bot's username
|
USERNAME = config['AUTH']['username'] # Bot's username
|
||||||
|
@ -2049,16 +1919,20 @@ def main():
|
||||||
else:
|
else:
|
||||||
print("Probleme de lecture de configuration asmodee.ini (AUTH)")
|
print("Probleme de lecture de configuration asmodee.ini (AUTH)")
|
||||||
|
|
||||||
|
RTE_ID = None # Bot's RTE ID
|
||||||
|
RTE_SECRET = None # Bot's RTE SECRET
|
||||||
if ('RTE' in config):
|
if ('RTE' in config):
|
||||||
global RTE_ID
|
global oauth
|
||||||
global RTE_SECRET
|
|
||||||
global wattobj
|
global wattobj
|
||||||
RTE_ID = config['RTE']['client_id'] # Bot's username
|
RTE_ID = config['RTE']['client_id'] # Bot's username
|
||||||
RTE_SECRET = config['RTE']['client_secret'] # Bot's password
|
RTE_SECRET = config['RTE']['client_secret'] # Bot's password
|
||||||
|
auth = HTTPBasicAuth(RTE_ID, RTE_SECRET)
|
||||||
|
client = BackendApplicationClient(client_id=RTE_ID)
|
||||||
|
oauth = OAuth2Session(client=client)
|
||||||
|
token = oauth.fetch_token(token_url='https://digital.iservices.rte-france.com/token/oauth/', auth=auth)
|
||||||
wattobj = Wattobject()
|
wattobj = Wattobject()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
RTE_ID = None
|
|
||||||
RTE_SECRET = None
|
|
||||||
print("Probleme de lecture de configuration asmodee.ini (RTE)")
|
print("Probleme de lecture de configuration asmodee.ini (RTE)")
|
||||||
|
|
||||||
global liste_mod
|
global liste_mod
|
||||||
|
|
Loading…
Reference in a new issue