Output type as an Enum (#35)

* Add enum34 requirement

* Use an Enum for output types
pull/37/head
Lucidiot 2018-10-10 19:25:03 +02:00 committed by Mal Hancock
parent 86eddea996
commit f65248f797
3 changed files with 15 additions and 4 deletions

View File

@ -222,12 +222,14 @@ class Bot(irc.bot.SingleServerIRCBot):
for msg in output.msg:
if len(msg.encode('UTF-8')) > 512:
self.logger.error('output message too long: {}'.format(msg))
elif output.msg_type == 'message':
elif output.msg_type == pinhook.plugin.OutputType.Message:
self.logger.debug('output message: {}'.format(msg))
c.privmsg(chan, msg)
elif output.msg_type == 'action':
elif output.msg_type == pinhook.plugin.OutputType.Action:
self.logger.debug('output action: {}'.format(msg))
c.action(chan, msg)
else:
self.logger.warning("Unsupported output type '{}'".format(output.msg_type))
time.sleep(.5)

View File

@ -1,7 +1,15 @@
from enum import Enum
cmds = {}
lstnrs = {}
class OutputType(Enum):
Message = 'message'
Action = 'action'
class Output:
def __init__(self, msg_type, msg):
self.msg_type = msg_type
@ -15,11 +23,11 @@ class Output:
def action(msg):
return Output('action', msg)
return Output(OutputType.Action, msg)
def message(msg):
return Output('message', msg)
return Output(OutputType.Message, msg)
def _add_plugin(command, func):

View File

@ -21,6 +21,7 @@ AUTHOR = 'M. Hancock'
# What packages are required for this module to be executed?
REQUIRED = [
'irc',
'enum34',
]
# The rest you shouldn't have to touch too much :)