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