This commit is contained in:
ThomasWeis
2022-08-14 20:52:31 +02:00
14 changed files with 183 additions and 45 deletions

View File

@@ -143,7 +143,6 @@ class Connection(object):
self.irc.send("USER botty botty botty :Botty \n".encode()) self.irc.send("USER botty botty botty :Botty \n".encode())
if (self.details.get_pwd() != ''): if (self.details.get_pwd() != ''):
self.send_to_user("NICKSERV", "identify " + self.details.get_nick() + " " + self.details.get_pwd() + ' ') self.send_to_user("NICKSERV", "identify " + self.details.get_nick() + " " + self.details.get_pwd() + ' ')
time.sleep(3)
self.irc.send("JOIN ".encode() + self.details.get_channel().encode() + '\r\n'.encode()) self.irc.send("JOIN ".encode() + self.details.get_channel().encode() + '\r\n'.encode())
self.irc.send("WHO ".encode() + self.details.get_channel().encode() + '\r\n'.encode()) self.irc.send("WHO ".encode() + self.details.get_channel().encode() + '\r\n'.encode())
self.irc.send("MODE ".encode()+self.details.get_nick().encode()+" -R".encode()+'\r\n'.encode()) self.irc.send("MODE ".encode()+self.details.get_nick().encode()+" -R".encode()+'\r\n'.encode())

View File

@@ -53,7 +53,7 @@ class FaustBot(object):
self.add_module(WordRunObserver.WordRunObserver()) self.add_module(WordRunObserver.WordRunObserver())
self.add_module(GiveIceObserver.GiveIceObserver()) self.add_module(GiveIceObserver.GiveIceObserver())
self.add_module(GiveDrinkToObserver.GiveDrinkToObserver()) self.add_module(GiveDrinkToObserver.GiveDrinkToObserver())
self.add_module(Greeter.Greeter()) self.add_module(Greeter.Greeter(self.config.greeting))
self.add_module(MathRunObserver.MathRunObserver()) self.add_module(MathRunObserver.MathRunObserver())
self.add_module(PartyObserver.PartyObserver()) self.add_module(PartyObserver.PartyObserver())
self.add_module(PrideObserver.PrideObserver()) self.add_module(PrideObserver.PrideObserver())

View File

@@ -44,7 +44,8 @@ class Config(object):
self._config_dict['blacklist'] = [] self._config_dict['blacklist'] = []
for module in blacklist: for module in blacklist:
self._config_dict['blacklist'].append(module.strip()) self._config_dict['blacklist'].append(module.strip())
if 'greeting' not in self._config_dict:
self._config_dict['greeting'] = "Hallo"
@property @property
def lang(self): def lang(self):
return self._config_dict["lang"] return self._config_dict["lang"]
@@ -76,3 +77,7 @@ class Config(object):
@property @property
def pwd(self): def pwd(self):
return self._config_dict['pwd'] return self._config_dict['pwd']
@property
def greeting(self):
return self._config_dict['greeting']

View File

@@ -0,0 +1,36 @@
import sqlite3
class DucksProvider(object):
_CREATE_TABLE = 'CREATE TABLE IF NOT EXISTS ducks (id INTEGER PRIMARY KEY, \
user TEXT, friends INTEGER, dead INTEGER)'
_GET_DUCKS = 'SELECT id, friends, dead FROM ducks WHERE user = ?'
_SAVE_OR_OVERWRITE = 'REPLACE INTO ducks (id, user, friends, dead) VALUES (?, ?, ?,?)'
_DELETE_DUCKS = 'DELETE FROM ducks WHERE user = ?'
def __init__(self):
self._database_connection = sqlite3.connect('faust_bot.db')
cursor = self._database_connection.cursor()
cursor.execute(DucksProvider._CREATE_TABLE)
self._database_connection.commit()
def get_ducks(self, user: str):
cursor = self._database_connection.cursor()
cursor.execute(DucksProvider._GET_DUCKS, (user.lower(),))
return cursor.fetchone()
def save_or_replace(self, user: str, friends: int, dead: int):
existing = self.get_ducks(user)
_id = existing[0] if existing is not None else None
data = (_id, user.lower(), friends, dead)
cursor = self._database_connection.cursor()
cursor.execute(DucksProvider._SAVE_OR_OVERWRITE, data)
self._database_connection.commit()
def delete_score(self, user: str):
cursor = self._database_connection.cursor()
cursor.execute(DucksProvider._DELETE_DUCKS, (user.lower(),))
self._database_connection.commit()
def __exit__(self):
self._database_connection.close()

View File

@@ -4,7 +4,6 @@ from collections import defaultdict
from FaustBot.Communication.Connection import Connection from FaustBot.Communication.Connection import Connection
from FaustBot.Model.UserProvider import UserProvider from FaustBot.Model.UserProvider import UserProvider
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
from ..Model.i18n import i18n
from FaustBot.Modules.UserList import UserList from FaustBot.Modules.UserList import UserList
class AllSeenObserver(PrivMsgObserverPrototype): class AllSeenObserver(PrivMsgObserverPrototype):

View File

@@ -1,10 +1,5 @@
import datetime
import time
from FaustBot.Communication.Connection import Connection from FaustBot.Communication.Connection import Connection
from FaustBot.Model.UserProvider import UserProvider
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
from ..Model.i18n import i18n
from FaustBot.Model.BlockedUsers import BlockProvider from FaustBot.Model.BlockedUsers import BlockProvider
class BlockObserver(PrivMsgObserverPrototype): class BlockObserver(PrivMsgObserverPrototype):

View File

@@ -3,7 +3,7 @@ from FaustBot.Communication.Connection import Connection
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
from FaustBot.Modules.PingObserverPrototype import PingObserverPrototype from FaustBot.Modules.PingObserverPrototype import PingObserverPrototype
from random import randint from random import randint
from collections import defaultdict from FaustBot.Model.DuckProvider import DucksProvider
class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype): class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
@staticmethod @staticmethod
@@ -12,9 +12,7 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
@staticmethod @staticmethod
def help(): def help():
return 'Entenjagd. An einem zufälligen Zeitpunkt watschelt eine Ente durch den Chat. ' + \ return 'duck game'
'Diese kann mit .schiessen getötet oder mit .freunde angefreundet werden. Mit .ducks wird abgefragt, wie viele Enten man schon hat. ' + \
'Starten und stoppen können nur Moderatoren.'
@staticmethod @staticmethod
def get_module_types(): def get_module_types():
@@ -24,30 +22,31 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
super().__init__() super().__init__()
self.active = 0 self.active = 0
self.duck_alive = 0 self.duck_alive = 0
self.ducks_hunt = defaultdict(int) self.streak = 0
self.ducks_befriend = defaultdict(int) self.streakname = ""
def update_on_priv_msg(self, data, connection: Connection): def update_on_priv_msg(self, data, connection: Connection):
if data['message'].startswith('.starthunt'): if data['message'].find('.starthunt') != -1:
if not self._is_idented_mod(data, connection): if not self._is_idented_mod(data, connection):
connection.send_back("Dir fehlen leider die Rechte zum Starten der Jagd, " + data['nick'] + ".",data) connection.send_back("Dir fehlen leider die Rechte zum Starten der Jagd, " + data['nick'] + ".",data)
return return
self.active = 1 self.active = 1
connection.send_channel("Jagd eröffnet") connection.send_channel("Jagd eröffnet")
return return
if data['message'].startswith('.stophunt'): if data['message'].find('.stophunt') != -1:
if not self._is_idented_mod(data, connection): if not self._is_idented_mod(data, connection):
connection.send_back("Dir fehlen leider die Rechte zum Stoppen der Jagd, " + data['nick'] + ".", data) connection.send_back("Dir fehlen leider die Rechte zum Stoppen der Jagd, " + data['nick'] + ".",
data)
return return
self.active = 0 self.active = 0
self.duck_alive = 0 self.duck_alive = 0
connection.send_channel("Jagd beendet") connection.send_channel("Jagd beendet")
return return
if data['message'].startswith('.ducks'): if data['message'].find('.ducks') != -1:
connection.send_channel(data['nick'] + " hat schon " + str(self.ducks_befriend[data['nick']]) + " befreundete Enten und " + str(self.ducks_hunt[data['nick']]) + " getötete Enten.") connection.send_channel(self.build_duck_string(data['nick']))
if data['message'].startswith('.freunde'): if data['message'].find('.freunde') != -1:
self.befriend(data, connection) self.befriend(data, connection)
if data['message'].startswith('.schiessen'): if data['message'].find('.schiessen') != -1:
self.shoot(data, connection) self.shoot(data, connection)
def befriend(self, data, connection): def befriend(self, data, connection):
@@ -56,8 +55,9 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
connection.send_channel(data['nick'] + " probiert eine Ente zu befreunden aber sie will nicht.") connection.send_channel(data['nick'] + " probiert eine Ente zu befreunden aber sie will nicht.")
else: else:
self.duck_alive = 0 self.duck_alive = 0
self.ducks_befriend[data['nick']] += 1 self.addLivingDuck(data['nick'])
connection.send_channel(data['nick'] + " hat schon " + str(self.ducks_befriend[data['nick']]) + " befreundete Enten und " + str(self.ducks_hunt[data['nick']]) + " getötete Enten.") connection.send_channel(self.build_duck_string(data['nick']))
self.duckAchievments(data['nick'], connection)
return return
if (self.duck_alive == 0 and self.active == 1): if (self.duck_alive == 0 and self.active == 1):
connection.send_channel(data['nick']+ " probiert eine nicht existente Ente zu befreunden.") connection.send_channel(data['nick']+ " probiert eine nicht existente Ente zu befreunden.")
@@ -69,8 +69,9 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
connection.send_channel(data['nick'] + " trifft daneben.") connection.send_channel(data['nick'] + " trifft daneben.")
else: else:
self.duck_alive = 0 self.duck_alive = 0
self.ducks_hunt[data['nick']] += 1 self.addDeadDuck(data['nick'])
connection.send_channel(data['nick'] + " hat schon " + str(self.ducks_befriend[data['nick']]) + " befreundete Enten und " + str(self.ducks_hunt[data['nick']]) + " getötete Enten.") connection.send_channel(self.build_duck_string(data['nick']))
self.duckAchievments(data['nick'], connection)
return return
if (self.duck_alive == 0 and self.active == 1): if (self.duck_alive == 0 and self.active == 1):
connection.send_channel(data['nick']+ " schießt ins Nichts.") connection.send_channel(data['nick']+ " schießt ins Nichts.")
@@ -80,10 +81,118 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
def update_on_ping(self, data, connection: Connection): def update_on_ping(self, data, connection: Connection):
if self.active == 0: if self.active == 0:
return return
if 1 == randint(1,11): if 1 == randint(1,15):
if self.duck_alive == 0: if self.duck_alive == 0:
connection.send_channel("*. *. *. * <<w°)> *. *. * Quack!") connection.send_channel("*. *. *. * <<w°)> *. *. * Quack!")
self.duck_alive = 1 self.duck_alive = 1
def _is_idented_mod(self, data: dict, connection: Connection): def _is_idented_mod(self, data: dict, connection: Connection):
return data['nick'] in self._config.mods and connection.is_idented(data['nick']) return data['nick'] in self._config.mods and connection.is_idented(data['nick'])
def getLiving(self, nick: str):
duck_provider = DucksProvider()
duck = duck_provider.get_ducks(nick)
if duck is not None:
return duck[1]
else:
return 0
def getDead(self, nick: str):
duck_provider = DucksProvider()
duck = duck_provider.get_ducks(nick)
if duck is not None:
return duck[2]
else:
return 0
def addDeadDuck(self, nick:str):
self.writeDucks(nick, self.getLiving(nick), self.getDead(nick)+1)
def addLivingDuck(self,nick:str):
self.writeDucks(nick, self.getLiving(nick)+1, self.getDead(nick))
def writeDucks(self, nick: str, living: int, dead: int):
ducks_provider = DucksProvider()
ducks_provider.save_or_replace(nick, living, dead)
def build_duck_string(self, nick: str):
duckstring = ""
livingDucks = self.getLiving(nick)
deadDucks = self.getDead(nick)
if livingDucks > 1:
duckstring = duckstring + nick + " hat schon " +str(livingDucks)+ " befreundete Enten und "
elif livingDucks == 1:
duckstring = duckstring + nick + " hat schon eine befreundete Ente und "
elif livingDucks == 0:
duckstring = duckstring + nick + " hat noch keine befreundeten Enten und "
if deadDucks > 1:
duckstring = duckstring + str(deadDucks) + " getötete Enten"
elif deadDucks == 1:
duckstring = duckstring +"eine getötete Ente"
elif deadDucks == 0:
duckstring = duckstring+"keine getöteten Enten"
return duckstring
def duckAchievments(self, nick, connection):
dead = self.getDead(nick)
living = self.getLiving(nick)
if dead == 0:
if living == 5:
connection.send_channel(nick + " hat den Titel 'kleiner Entenfreund' erreicht")
elif living == 66:
connection.send_channel(nick + " hat den Titel 'Entenfreund' erreicht")
elif living == 111:
connection.send_channel(nick + " hat den Titel 'großer Entenfreund' erreicht")
elif living == 555:
connection.send_channel(nick + " hat den Titel 'Kleiner Entenmonarch' erreicht")
elif living == 1111:
connection.send_channel(nick + " hat den Titel 'Entenmonarch' erreicht")
elif living == 2222:
connection.send_channel(nick + " hat den Titel 'großer Entenmonarch' erreicht")
elif living == 3333:
connection.send_channel(nick + " hat den Titel 'Enten verehren dich als ihre Gottheit!' erreicht")
if living == 0:
if dead == 5:
connection.send_channel(nick + " hat den Titel 'kleiner Entenmörder' erreicht")
elif dead == 66:
connection.send_channel(nick + " hat den Titel 'Entenmörder' erreicht")
elif dead == 111:
connection.send_channel(nick + " hat den Titel 'großer Entenmörder' erreicht")
elif dead == 555:
connection.send_channel(nick + " hat den Titel 'kleiner Entenmassenmörder' erreicht")
elif dead == 1111:
connection.send_channel(nick + " hat den Titel 'Entenmassenmörder' erreicht")
elif dead == 2222:
connection.send_channel(nick + " hat den Titel 'großer Entenmassenmörder' erreicht")
elif dead == 3333:
connection.send_channel(nick + " hat den Titel 'du musst Enten wirklich hassen' erreicht")
if dead > 0 and living > 0:
if living + dead == 5:
connection.send_channel(nick + " hat den Titel 'Enten könnten Angst vor dir haben' erreicht")
elif living+ dead == 66:
connection.send_channel(nick + " hat den Titel 'Enten, Enten. So viele Enten' erreicht")
elif living + dead == 111:
connection.send_channel(nick + " hat den Titel 'Ich liebe Enten' erreicht")
elif living + dead == 555:
connection.send_channel(nick + " hat den Titel 'Auf dem Grill und als Freund. Enten sind mein Leben' erreicht")
elif living + dead == 1111:
connection.send_channel(nick + " hat den Titel 'Durchgespielt' erreicht")
elif living + dead == 2222:
connection.send_channel(nick + " hat den Titel 'Immernoch im Spiel' erreicht")
elif living + dead == 3333:
connection.send_channel(nick + " hat den Titel 'Alter!' erreicht")
if nick == self.streakname:
self.streak+=1
else:
self.streak = 1
self.streakname = nick
if self.streak == 3:
connection.send_channel(nick + " hat einen Lauf")
elif self.streak == 5:
connection.send_channel(nick + " ist nicht aufhaltbar")
elif self.streak == 15:
connection.send_channel(nick + " spielt wohl allein")

View File

@@ -16,9 +16,10 @@ class Greeter(JoinObserverPrototype):
def help(): def help():
return None return None
def __init__(self): def __init__(self, greeting):
super().__init__() super().__init__()
self.names = defaultdict(int) self.names = defaultdict(int)
self.greeting = greeting
def update_on_join(self, data, connection: Connection): def update_on_join(self, data, connection: Connection):
if data['channel'] == connection.details.get_channel(): if data['channel'] == connection.details.get_channel():
@@ -27,5 +28,5 @@ class Greeter(JoinObserverPrototype):
connection.send_back("Herzlich Willkommen bei uns "+data['nick'],data) connection.send_back("Herzlich Willkommen bei uns "+data['nick'],data)
self.names[data['nick']] = int(time.time()) self.names[data['nick']] = int(time.time())
return return
connection.send_back("Hallo " + data['nick'], data) connection.send_back(self.greeting+" " + data['nick'], data)
self.names[data['nick']] = int(time.time()) self.names[data['nick']] = int(time.time())

View File

@@ -1,4 +1,3 @@
from types import NoneType
from FaustBot.Communication import Connection from FaustBot.Communication import Connection
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype

View File

@@ -1,10 +1,8 @@
import datetime import datetime
import time
from FaustBot.Communication.Connection import Connection from FaustBot.Communication.Connection import Connection
from FaustBot.Model.UserProvider import UserProvider from FaustBot.Model.UserProvider import UserProvider
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
from ..Model.i18n import i18n
class SeenObserver(PrivMsgObserverPrototype): class SeenObserver(PrivMsgObserverPrototype):

View File

@@ -1,6 +1,4 @@
from wikipedia import wikipedia from wikipedia import wikipedia
from FaustBot.Model.i18n import i18n
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
@@ -17,18 +15,16 @@ class WikiObserver(PrivMsgObserverPrototype):
if data['message'].find('.w ') == -1: if data['message'].find('.w ') == -1:
return return
i18n_server = i18n() w = wikipedia.set_lang('de')
w = wikipedia.set_lang(i18n_server.get_text('wiki_lang', lang=self.config.lang))
q = data['message'].split(' ') q = data['message'].split(' ')
query = '' query = ''
for word in q: for word in q:
if word.strip() != '.w': if word.strip() != '.w':
query += word + ' ' query += word + ' '
w = wikipedia.search(query) w = wikipedia.search(query)
if w.__len__() == 0: # TODO BUG BELOW, ERROR MESSAGE NOT SHOWN! if w.__len__() == 0:
connection.send_back(data['nick'] + ', ' + connection.send_back(data['nick'] + ', ' +
i18n_server.get_text('wiki_fail', 'ich habe dazu keinen eintrag gefunden!',
lang=self.config.lang),
data) data)
return return
try: try:

View File

@@ -28,7 +28,7 @@ essen = ['einen Wirsingeintopf', 'einen Lahmacun', 'eine Portion Kartoffelbrei',
'eine Waffel mit Puderzucker', 'Grießbrei mit Amarena Kirschen', 'eine Waffel mit Puderzucker', 'Grießbrei mit Amarena Kirschen',
'einen Kaiserschmarrn mit Apfelmus', 'Palatschinken mit Marillenmarmelade und Staubzucker', 'einen Kaiserschmarrn mit Apfelmus', 'Palatschinken mit Marillenmarmelade und Staubzucker',
'eine Tüte Maiswaffeln','eine Packung Schoko Keksi','einen Handkäs mit Musik', 'eine Tüte Maiswaffeln','eine Packung Schoko Keksi','einen Handkäs mit Musik',
'eine Schale Grießbrei mit Nutella' 'eine Schale Grießbrei mit Nutella','ein Gefäß mit Wan Tan'
] ]

View File

@@ -45,5 +45,6 @@ getraenke = ['einen Kaffee','eine Limonade','einen Kakao','einen Tee',
'ein Glas fairtrade Limonade','eine Cola Light', 'ein Glas Fanta light', 'ein Glas fairtrade Limonade','eine Cola Light', 'ein Glas Fanta light',
'ein Glas Sprite light', 'ein Glas Spezi light','eine dampfende Tasse Winterpunsch-Tee', 'ein Glas Sprite light', 'ein Glas Spezi light','eine dampfende Tasse Winterpunsch-Tee',
'eine bunte Tasse Rooibos Schoko-Chai','eine Tasse Rooibos Chai', 'eine bunte Tasse Rooibos Schoko-Chai','eine Tasse Rooibos Chai',
'eine Tasse Fencheltee mit Honig' 'eine Tasse Fencheltee mit Honig','eine dampfende Tasse Zimtschneckentee',
'eine dampfende Tasse gebrannte Mandel Tee'
] ]