Removed subclass

This commit is contained in:
gpkvt 2022-08-28 12:33:46 +02:00
parent c759c78f7f
commit 290a09be5d
1 changed files with 532 additions and 530 deletions

142
tts.py
View File

@ -58,9 +58,7 @@ class IRC:
}
self.quickvote = {
"status": False,
"message": False
}
self.poll = {
"message": False,
"count": 0,
"data": {}
}
@ -241,30 +239,30 @@ class IRC:
if msg.startswith('#') and self.quickvote['status'] is True:
logging.info('Quickvote: Cast detected')
self.poll['count'] += 1
self.poll['data'][user] = msg.lower()
logging.debug("poll: %s", self.poll)
self.quickvote['count'] += 1
self.quickvote['data'][user] = msg.lower()
logging.debug("quickvote: %s", self.quickvote)
return
if msg.startswith('!tts'):
logging.info('!tts command detected')
self.Commands.tts(self, message, tags)
self.ttscmd(message, tags)
return
if msg.startswith('!wiki') and CONF['FEATURE']['WIKI']:
logging.debug("!wiki command detected")
self.Commands.wiki(self, tags, msg)
self.wiki(tags, msg)
return
if CONF['FEATURE']['QUOTE']:
if msg.startswith('!addquote'):
logging.debug("!addquote command detected")
self.Commands.addquote(self, tags, msg)
self.addquote(tags, msg)
return
if msg.startswith('!smartquote') or msg.startswith('!sq'):
logging.debug("!smartquote command detected")
self.Commands.quote(self, tags, msg)
self.quote(tags, msg)
return
def priviledged_commands(self, message, tags):
@ -319,31 +317,31 @@ class IRC:
elif msg.startswith('!pick') and CONF['FEATURE']['PICK']:
logging.debug("!pick command detected")
self.Commands.pick(self, msg)
self.pickcmd(msg)
elif msg.startswith('!random') and CONF['FEATURE']['RANDOM']:
logging.info('!random command detected')
self.Commands.random(self, msg)
self.random(msg)
elif msg.startswith('!quickvote') and CONF['FEATURE']['QUOTE']:
logging.info("!quickvote command detected")
self.Commands.quickvote(self, msg)
self.quickvotecmd(msg)
elif msg.startswith('!ptts'):
logging.debug("!ptts command detected")
self.Commands.ptts(self, msg)
self.ptts(msg)
elif msg.startswith('!dtts'):
logging.debug("!dtts command detected")
self.Commands.dtts(self, msg)
self.dtts(msg)
elif msg.startswith('!usermap'):
logging.info('!usermap command detected')
self.Commands.usermap(self, msg)
self.usermap(msg)
elif msg.startswith('!delay'):
logging.info('!delay command detected')
self.Commands.delay(self, msg)
self.delay(msg)
def check_subonly(self, tags):
""" Check if subonly mode is enabled and sender is sub
@ -538,22 +536,7 @@ class IRC:
if resp.find('PRIVMSG') != -1:
self.resp_privmsg(resp)
class Commands():
""" Bot commands """
def __init__(self):
self.tts_denied = []
self.tts_allowed = []
self.quickvote_status = self.quickvote_status
self.pick_status = self.pick_status
self.votemsg = self.votemsg
self.poll = self.poll
self.pollcount = self.pollcount
self.pickme = self.pickme
self.picknumber = self.picknumber
self.pickcount = self.pickcount
def tts(self, msg, tags):
def ttscmd(self, msg, tags):
""" !tts command
Check if message is valid and send it to queue
@ -847,7 +830,7 @@ class IRC:
yaml.safe_dump(cur_yaml, yamlfile)
load_config()
def pick(self, msg):
def pickcmd(self, msg):
""" !pick command
Pick a number of users who typed #pickme in the chat
@ -856,16 +839,19 @@ class IRC:
:param str msg: Number of users to pick
"""
if self.pick_status:
if self.pick['status']:
logging.info('Pick stopped')
logging.debug("Got %s participats, wanted %s", self.pickcount, self.picknumber)
logging.debug("Got %s participats, wanted %s",
self.pick['count'],
self.pick['number']
)
try:
if int(self.pickcount) > int(self.picknumber):
picks = random.sample(self.pickme, self.picknumber)
if int(self.pick['count']) > int(self.pick['number']):
picks = random.sample(self.pick['pickme'], self.pick['number'])
logging.info('Got more than the requested number of participants')
else:
picks = self.pickme
picks = self.pick['pickme']
logging.info('Got less than or exactly the \
requested number of participants')
@ -904,21 +890,21 @@ class IRC:
CONF['MESSAGE']['PICKNONE']
)
self.pick_status = False
self.pickme = []
self.pickcount = 0
self.pick['status'] = False
self.pick['pickme'] = []
self.pick['count'] = 0
return
logging.debug('Pick started')
self.pick_status = True
self.pick['status'] = True
try:
msg = msg.split(' ')[1].strip()
self.picknumber = msg
self.pick['number'] = msg
except IndexError:
self.picknumber = self.picknumber
self.pick['number'] = self.pick['number']
logging.info("Will pick %s participants", self.picknumber)
logging.info("Will pick %s participants", self.pick['number'])
IRC.sendmsg(self,
CONF['IRC_CHANNEL'], "@chat",
@ -926,7 +912,7 @@ class IRC:
)
return
def quickvote(self, msg):
def quickvotecmd(self, msg):
""" !quickvote command
Starts or stops the !quickvote function. On stop calculates the 5 most casted
@ -935,13 +921,23 @@ class IRC:
:param str msg: The IRC message triggering the command
"""
if self.quickvote_status:
if self.quickvote['status']:
logging.debug('Quickvote stopped')
if self.pollcount == 0:
if self.quickvote['count'] == 0:
logging.info("Nobody voted")
IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@chat", CONF['MESSAGE']['VOTEEND'])
IRC.sendmsg(self, CONF['IRC_CHANNEL'], "*", CONF['MESSAGE']['VOTENOBODY'])
IRC.sendmsg(
self,
CONF['IRC_CHANNEL'],
"@chat",
CONF['MESSAGE']['VOTEEND']
)
IRC.sendmsg(
self,
CONF['IRC_CHANNEL'],
"*",
CONF['MESSAGE']['VOTENOBODY']
)
raw_msg = {
"TTS": True,
@ -959,13 +955,13 @@ class IRC:
logging.info('The result is: %s', CONF['MESSAGE']['VOTENOBODY'])
logging.debug('Votemsg: %s', msg)
self.quickvote_status = False
self.poll = {}
self.quickvote['status'] = False
self.quickvote['data'] = {}
return
logging.info("Counting votes")
count = 0
count = Counter(self.poll.values()).most_common(5)
count = Counter(self.quickvote['data'].values()).most_common(5)
IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@chat", CONF['MESSAGE']['VOTEEND'])
logging.debug(count)
@ -996,21 +992,27 @@ class IRC:
message
)
self.quickvote_status = False
self.poll = {}
self.pollcount = 0
self.quickvote['status'] = False
self.quickvote['data'] = {}
self.quickvote['count'] = 0
return
logging.debug('Quickvote started')
self.quickvote_status = True
self.votemsg = msg.split('!quickvote', 1)[1].strip()
if self.votemsg:
IRC.sendmsg(self,
self.quickvote['status'] = True
self.quickvote['message'] = msg.split('!quickvote', 1)[1].strip()
if self.quickvote['message']:
IRC.sendmsg(
self,
CONF['IRC_CHANNEL'], "@chat",
CONF['MESSAGE']['VOTESTART'] + " (" + str(self.votemsg) + ")"
CONF['MESSAGE']['VOTESTART'] + " (" + str(self.quickvote['message']) + ")"
)
else:
IRC.sendmsg(self, CONF['IRC_CHANNEL'], "@chat", CONF['MESSAGE']['VOTESTART'])
IRC.sendmsg(
self,
CONF['IRC_CHANNEL'],
"@chat",
CONF['MESSAGE']['VOTESTART']
)
return
@ -1070,11 +1072,11 @@ class IRC:
user = user.replace('@', '')
logging.info("Adding %s to whitelist", user)
self.tts_allowed.append(user)
self.tts['whitelist'].append(user)
if user in self.tts_denied:
if user in self.tts['blacklist']:
logging.info("Removing %s from deny list", user)
self.tts_denied.remove(user)
self.tts['blacklist'].remove(user)
def dtts(self, msg):
""" !dtts command
@ -1090,13 +1092,13 @@ class IRC:
logging.debug('Removing "@" from username')
user = user.replace('@', '')
if user not in self.tts_denied:
if user not in self.tts['blacklist']:
logging.info("Adding %s to deny list", user)
self.tts_denied.append(user)
self.tts['blacklist'].append(user)
if user in self.tts_allowed:
if user in self.tts['whitelist']:
logging.info("Removing %s from allowed list", user)
self.tts_allowed.remove(user)
self.tts['whitelist'].remove(user)
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
""" Threaded HTTP Server """