mirror of
https://github.com/nichkara/InfinitumBotty.git
synced 2026-06-10 22:26:23 +02:00
Initalize repo
This commit is contained in:
94
FaustBot/Modules/CustomUserModules/GlossaryModule.py
Normal file
94
FaustBot/Modules/CustomUserModules/GlossaryModule.py
Normal file
@@ -0,0 +1,94 @@
|
||||
from FaustBot.Communication.Connection import Connection
|
||||
from FaustBot.Model.Config import Config
|
||||
from FaustBot.Model.GlossaryProvider import GlossaryProvider
|
||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||
from FaustBot.Modules.WikiObserver import WikiObserver
|
||||
|
||||
class GlossaryModule(PrivMsgObserverPrototype):
|
||||
@staticmethod
|
||||
def cmd():
|
||||
return [GlossaryModule._ADD_EXPLANATION,
|
||||
GlossaryModule._REMOVE_EXPLANATION,
|
||||
GlossaryModule._QUERY_EXPLANATION]
|
||||
|
||||
@staticmethod
|
||||
def help():
|
||||
return None
|
||||
|
||||
_QUERY_EXPLANATION = '.?'
|
||||
_REMOVE_EXPLANATION = '.?-'
|
||||
_ADD_EXPLANATION = '.?+'
|
||||
|
||||
def __init__(self, config: Config):
|
||||
super().__init__()
|
||||
self._config = config
|
||||
|
||||
def update_on_priv_msg(self, data, connection: Connection):
|
||||
msg = data['message']
|
||||
if not -1 == msg.find(GlossaryModule._REMOVE_EXPLANATION):
|
||||
self._remove_query(data, connection)
|
||||
elif not -1 == msg.find(GlossaryModule._ADD_EXPLANATION):
|
||||
self._add_query(data, connection)
|
||||
elif not -1 == msg.find(GlossaryModule._QUERY_EXPLANATION):
|
||||
self._answer_query(data, connection)
|
||||
|
||||
def _answer_query(self, data, connection: Connection):
|
||||
"""
|
||||
:param data:
|
||||
:param connection:
|
||||
:return:
|
||||
"""
|
||||
glossary_provider = GlossaryProvider()
|
||||
split = data['message'].split(GlossaryModule._QUERY_EXPLANATION)
|
||||
if not len(split) == 2:
|
||||
return
|
||||
answer = glossary_provider.get_explanation(split[1].strip())
|
||||
if answer is None or answer[1] is None or answer[1].strip() == '':
|
||||
if split[1].strip() == '':
|
||||
return
|
||||
# connection.send_back("Tut mir leid, " + data['nick'] + ". Für " + split[1].strip() +
|
||||
# " habe ich noch keinen Eintrag. Aber Wikipedia sagt dazu:", data)
|
||||
wikiObserver = WikiObserver()
|
||||
wikiObserver.config = self.config
|
||||
data2 = data.copy()
|
||||
data2['message'] = '.w '+split[1]+" \r\n"
|
||||
wikiObserver.update_on_priv_msg(data2, connection)
|
||||
else:
|
||||
connection.send_back(data['nick'] + ": " + split[1] + " - " + answer[1], data)
|
||||
|
||||
def _remove_query(self, data, connection: Connection):
|
||||
"""
|
||||
|
||||
:param data:
|
||||
:param connection:
|
||||
:return:
|
||||
"""
|
||||
if not self._is_idented_mod(data, connection):
|
||||
connection.send_back("Dir fehlen die Berechtigungen zum Löschen von Einträgen, " + data['nick'] + ".", data)
|
||||
return
|
||||
glossary_provider = GlossaryProvider()
|
||||
split = data['message'].split(GlossaryModule._REMOVE_EXPLANATION)
|
||||
if not len(split) == 2:
|
||||
return
|
||||
glossary_provider.delete_explanation(split[1])
|
||||
connection.send_back("Der Eintrag zu " + split[1] + " wurde gelöscht, " + data['nick'] + ".", data)
|
||||
|
||||
def _add_query(self, data, connection: Connection):
|
||||
"""
|
||||
|
||||
:param data:
|
||||
:param connection:
|
||||
:return:
|
||||
"""
|
||||
if not self._is_idented_mod(data, connection):
|
||||
connection.send_back("Dir fehlen leider die Rechte zum Hinzufügen von Einträgen, " + data['nick'] + ".",
|
||||
data)
|
||||
return
|
||||
msg = data['message'].split(GlossaryModule._ADD_EXPLANATION)[1].strip()
|
||||
split = msg.split(' ', 1)
|
||||
glossary_provider = GlossaryProvider()
|
||||
glossary_provider.save_or_replace(split[0], split[1])
|
||||
connection.send_back(data['nick'] + ": der Eintrag zu " + split[0] + " wurde gespeichert.", data)
|
||||
|
||||
def _is_idented_mod(self, data: dict, connection: Connection):
|
||||
return data['nick'] in self._config.mods and connection.is_idented(data['nick'])
|
||||
42
FaustBot/Modules/CustomUserModules/ICDObserver.py
Normal file
42
FaustBot/Modules/CustomUserModules/ICDObserver.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import csv
|
||||
import re
|
||||
|
||||
from FaustBot.Communication.Connection import Connection
|
||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||
|
||||
|
||||
class ICDObserver(PrivMsgObserverPrototype):
|
||||
@staticmethod
|
||||
def cmd():
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def help():
|
||||
return None
|
||||
|
||||
def get_icd(self, code):
|
||||
if code == "C64" or code == "P20":
|
||||
return ""
|
||||
icd10_codes = open('care_icd10_de.csv', 'r',encoding='utf8')
|
||||
icd10 = csv.reader(icd10_codes, delimiter=';', quotechar='"')
|
||||
for row in icd10:
|
||||
if row[0] == code:
|
||||
return code +' - ' + row[1]
|
||||
return 0
|
||||
|
||||
def update_on_priv_msg(self, data, connection: Connection):
|
||||
if data['channel'] != connection.details.get_channel():
|
||||
return
|
||||
regex = r'\b(\w\d{2}\.?\d?\d?)\b'
|
||||
codes = re.findall(regex, data['message'])
|
||||
for code in codes:
|
||||
code = code.capitalize()
|
||||
text = self.get_icd(code)
|
||||
if text == 0:
|
||||
if code.find('.') != -1:
|
||||
code += '-'
|
||||
else:
|
||||
code += '.-'
|
||||
text = self.get_icd(code)
|
||||
if text != 0:
|
||||
connection.send_back(text, data)
|
||||
21
FaustBot/Modules/CustomUserModules/ModmailObserver.py
Normal file
21
FaustBot/Modules/CustomUserModules/ModmailObserver.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from FaustBot.Communication.Connection import Connection
|
||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||
|
||||
|
||||
class ModmailObserver(PrivMsgObserverPrototype):
|
||||
@staticmethod
|
||||
def cmd():
|
||||
return [".modmail"]
|
||||
|
||||
@staticmethod
|
||||
def help():
|
||||
return ".modmail <msg> - Sendet allen Moderatoren <msg> per PN"
|
||||
|
||||
def update_on_priv_msg(self, data, connection: Connection):
|
||||
if data['message'].find('.modmail') == -1:
|
||||
return
|
||||
mods = connection.details.get_mods()
|
||||
print(mods)
|
||||
message = data['message'].split('.modmail ')[1]
|
||||
for mod in mods:
|
||||
connection.send_to_user(mod, data['nick'] + ' meldet: ' + message)
|
||||
0
FaustBot/Modules/CustomUserModules/__init__.py
Normal file
0
FaustBot/Modules/CustomUserModules/__init__.py
Normal file
Reference in New Issue
Block a user