mirror of
https://github.com/nichkara/InfinitumBotty.git
synced 2026-06-11 06:36:24 +02:00
Merge branch 'main' of https://github.com/ThomasWeis/InfinitumBotty
This commit is contained in:
@@ -4,7 +4,6 @@ from collections import defaultdict
|
||||
from FaustBot.Communication.Connection import Connection
|
||||
from FaustBot.Model.UserProvider import UserProvider
|
||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||
from ..Model.i18n import i18n
|
||||
from FaustBot.Modules.UserList import UserList
|
||||
|
||||
class AllSeenObserver(PrivMsgObserverPrototype):
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import datetime
|
||||
import time
|
||||
|
||||
from FaustBot.Communication.Connection import Connection
|
||||
from FaustBot.Model.UserProvider import UserProvider
|
||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||
from ..Model.i18n import i18n
|
||||
from FaustBot.Model.BlockedUsers import BlockProvider
|
||||
|
||||
class BlockObserver(PrivMsgObserverPrototype):
|
||||
|
||||
@@ -3,7 +3,7 @@ from FaustBot.Communication.Connection import Connection
|
||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||
from FaustBot.Modules.PingObserverPrototype import PingObserverPrototype
|
||||
from random import randint
|
||||
from collections import defaultdict
|
||||
from FaustBot.Model.DuckProvider import DucksProvider
|
||||
|
||||
class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
|
||||
@staticmethod
|
||||
@@ -12,9 +12,7 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
|
||||
|
||||
@staticmethod
|
||||
def help():
|
||||
return 'Entenjagd. An einem zufälligen Zeitpunkt watschelt eine Ente durch den Chat. ' + \
|
||||
'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.'
|
||||
return 'duck game'
|
||||
|
||||
@staticmethod
|
||||
def get_module_types():
|
||||
@@ -24,30 +22,31 @@ class DuckObserver(PrivMsgObserverPrototype, PingObserverPrototype):
|
||||
super().__init__()
|
||||
self.active = 0
|
||||
self.duck_alive = 0
|
||||
self.ducks_hunt = defaultdict(int)
|
||||
self.ducks_befriend = defaultdict(int)
|
||||
self.streak = 0
|
||||
self.streakname = ""
|
||||
|
||||
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):
|
||||
connection.send_back("Dir fehlen leider die Rechte zum Starten der Jagd, " + data['nick'] + ".",data)
|
||||
return
|
||||
self.active = 1
|
||||
connection.send_channel("Jagd eröffnet")
|
||||
return
|
||||
if data['message'].startswith('.stophunt'):
|
||||
if data['message'].find('.stophunt') != -1:
|
||||
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
|
||||
self.active = 0
|
||||
self.duck_alive = 0
|
||||
connection.send_channel("Jagd beendet")
|
||||
return
|
||||
if data['message'].startswith('.ducks'):
|
||||
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.")
|
||||
if data['message'].startswith('.freunde'):
|
||||
if data['message'].find('.ducks') != -1:
|
||||
connection.send_channel(self.build_duck_string(data['nick']))
|
||||
if data['message'].find('.freunde') != -1:
|
||||
self.befriend(data, connection)
|
||||
if data['message'].startswith('.schiessen'):
|
||||
if data['message'].find('.schiessen') != -1:
|
||||
self.shoot(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.")
|
||||
else:
|
||||
self.duck_alive = 0
|
||||
self.ducks_befriend[data['nick']] += 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.")
|
||||
self.addLivingDuck(data['nick'])
|
||||
connection.send_channel(self.build_duck_string(data['nick']))
|
||||
self.duckAchievments(data['nick'], connection)
|
||||
return
|
||||
if (self.duck_alive == 0 and self.active == 1):
|
||||
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.")
|
||||
else:
|
||||
self.duck_alive = 0
|
||||
self.ducks_hunt[data['nick']] += 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.")
|
||||
self.addDeadDuck(data['nick'])
|
||||
connection.send_channel(self.build_duck_string(data['nick']))
|
||||
self.duckAchievments(data['nick'], connection)
|
||||
return
|
||||
if (self.duck_alive == 0 and self.active == 1):
|
||||
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):
|
||||
if self.active == 0:
|
||||
return
|
||||
if 1 == randint(1,11):
|
||||
if 1 == randint(1,15):
|
||||
if self.duck_alive == 0:
|
||||
connection.send_channel("*. *. *. * <<w°)> *. *. * Quack!")
|
||||
self.duck_alive = 1
|
||||
|
||||
def _is_idented_mod(self, data: dict, connection: Connection):
|
||||
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")
|
||||
|
||||
@@ -16,9 +16,10 @@ class Greeter(JoinObserverPrototype):
|
||||
def help():
|
||||
return None
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, greeting):
|
||||
super().__init__()
|
||||
self.names = defaultdict(int)
|
||||
self.greeting = greeting
|
||||
|
||||
def update_on_join(self, data, connection: Connection):
|
||||
if data['channel'] == connection.details.get_channel():
|
||||
@@ -27,5 +28,5 @@ class Greeter(JoinObserverPrototype):
|
||||
connection.send_back("Herzlich Willkommen bei uns "+data['nick'],data)
|
||||
self.names[data['nick']] = int(time.time())
|
||||
return
|
||||
connection.send_back("Hallo " + data['nick'], data)
|
||||
connection.send_back(self.greeting+" " + data['nick'], data)
|
||||
self.names[data['nick']] = int(time.time())
|
||||
@@ -1,4 +1,3 @@
|
||||
from types import NoneType
|
||||
from FaustBot.Communication import Connection
|
||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import datetime
|
||||
import time
|
||||
|
||||
from FaustBot.Communication.Connection import Connection
|
||||
from FaustBot.Model.UserProvider import UserProvider
|
||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||
from ..Model.i18n import i18n
|
||||
|
||||
|
||||
class SeenObserver(PrivMsgObserverPrototype):
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
from wikipedia import wikipedia
|
||||
|
||||
from FaustBot.Model.i18n import i18n
|
||||
from FaustBot.Modules.PrivMsgObserverPrototype import PrivMsgObserverPrototype
|
||||
|
||||
|
||||
@@ -17,18 +15,16 @@ class WikiObserver(PrivMsgObserverPrototype):
|
||||
|
||||
if data['message'].find('.w ') == -1:
|
||||
return
|
||||
i18n_server = i18n()
|
||||
w = wikipedia.set_lang(i18n_server.get_text('wiki_lang', lang=self.config.lang))
|
||||
w = wikipedia.set_lang('de')
|
||||
q = data['message'].split(' ')
|
||||
query = ''
|
||||
for word in q:
|
||||
if word.strip() != '.w':
|
||||
query += word + ' '
|
||||
w = wikipedia.search(query)
|
||||
if w.__len__() == 0: # TODO BUG BELOW, ERROR MESSAGE NOT SHOWN!
|
||||
if w.__len__() == 0:
|
||||
connection.send_back(data['nick'] + ', ' +
|
||||
i18n_server.get_text('wiki_fail',
|
||||
lang=self.config.lang),
|
||||
'ich habe dazu keinen eintrag gefunden!',
|
||||
data)
|
||||
return
|
||||
try:
|
||||
|
||||
@@ -28,11 +28,11 @@ class WordRunObserver(PrivMsgObserverPrototype):
|
||||
def update_on_priv_msg(self, data, connection: Connection):
|
||||
if data['message'].startswith('.a ') or data['message'].startswith('.add '):
|
||||
self.add(data, connection)
|
||||
if data['message'].startswith('.begin '):
|
||||
if data['message'].startswith('.begin '):
|
||||
self.begin_word(data, connection)
|
||||
if data['message'].startswith('.end '):
|
||||
if data['message'].startswith('.end '):
|
||||
self.end_word(data, connection)
|
||||
if data['message'].startswith('.wordrun'):
|
||||
if data['message'].startswith('.wordrun'):
|
||||
self.rules(data, connection)
|
||||
|
||||
def add(self, data, connection):
|
||||
|
||||
Reference in New Issue
Block a user