mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 15:09:54 -05:00
commit
4798514b44
@ -14,6 +14,7 @@ import aiml
|
|||||||
from .Database import db as botdb
|
from .Database import db as botdb
|
||||||
from .Config import config as botconfig
|
from .Config import config as botconfig
|
||||||
from .Read import read as botread
|
from .Read import read as botread
|
||||||
|
from .Users import users as botusers
|
||||||
|
|
||||||
from sopel_modules.spicemanip import spicemanip
|
from sopel_modules.spicemanip import spicemanip
|
||||||
|
|
||||||
@ -116,7 +117,7 @@ class SpiceBot_AI():
|
|||||||
|
|
||||||
def on_message(self, bot, trigger, message):
|
def on_message(self, bot, trigger, message):
|
||||||
nick = Identifier(trigger.nick)
|
nick = Identifier(trigger.nick)
|
||||||
nick_id = botdb.get_nick_id(nick, create=True)
|
nick_id = botusers.get_nick_id(nick, True)
|
||||||
self.check_user_import(nick, nick_id)
|
self.check_user_import(nick, nick_id)
|
||||||
|
|
||||||
message = self.bot_message_precipher(bot, trigger, message)
|
message = self.bot_message_precipher(bot, trigger, message)
|
||||||
@ -207,13 +208,13 @@ class SpiceBot_AI():
|
|||||||
def getPredicate(self, predicate, nick, nick_id=None):
|
def getPredicate(self, predicate, nick, nick_id=None):
|
||||||
if not nick_id:
|
if not nick_id:
|
||||||
nick = Identifier(nick)
|
nick = Identifier(nick)
|
||||||
nick_id = botdb.get_nick_id(nick, create=True)
|
nick_id = botusers.get_nick_id(nick, True)
|
||||||
self.aiml_kernel.getPredicate(predicate, nick_id)
|
self.aiml_kernel.getPredicate(predicate, nick_id)
|
||||||
|
|
||||||
def check_user_import(self, nick, nick_id=None):
|
def check_user_import(self, nick, nick_id=None):
|
||||||
if not nick_id:
|
if not nick_id:
|
||||||
nick = Identifier(nick)
|
nick = Identifier(nick)
|
||||||
nick_id = botdb.get_nick_id(nick, create=True)
|
nick_id = botusers.get_nick_id(nick, True)
|
||||||
if nick_id not in list(self.dict["sessioncache"].keys()):
|
if nick_id not in list(self.dict["sessioncache"].keys()):
|
||||||
self.dict["sessioncache"][nick_id] = botdb.get_nick_value(nick, 'botai') or {}
|
self.dict["sessioncache"][nick_id] = botdb.get_nick_value(nick, 'botai') or {}
|
||||||
for predicate in list(self.dict["sessioncache"][nick_id].keys()):
|
for predicate in list(self.dict["sessioncache"][nick_id].keys()):
|
||||||
@ -228,7 +229,7 @@ class SpiceBot_AI():
|
|||||||
def save_nick_session(self, nick, nick_id=None):
|
def save_nick_session(self, nick, nick_id=None):
|
||||||
if not nick_id:
|
if not nick_id:
|
||||||
nick = Identifier(nick)
|
nick = Identifier(nick)
|
||||||
nick_id = botdb.get_nick_id(nick, create=True)
|
nick_id = botusers.get_nick_id(nick, True)
|
||||||
sessionData = self.aiml_kernel.getSessionData(nick_id)
|
sessionData = self.aiml_kernel.getSessionData(nick_id)
|
||||||
botdb.set_nick_value(nick, 'botai', sessionData)
|
botdb.set_nick_value(nick, 'botai', sessionData)
|
||||||
|
|
||||||
|
|||||||
@ -21,44 +21,76 @@ class SpiceBot_Channels_MainSection(StaticSection):
|
|||||||
operadmin = ValidatedAttribute('operadmin', default=False)
|
operadmin = ValidatedAttribute('operadmin', default=False)
|
||||||
chanignore = ListAttribute('chanignore')
|
chanignore = ListAttribute('chanignore')
|
||||||
|
|
||||||
|
# replace process lock with uuid list system
|
||||||
|
|
||||||
|
|
||||||
class BotChannels():
|
class BotChannels():
|
||||||
"""This Logs all channels known to the server"""
|
"""This Logs all channels known to the server"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
|
# bot config setup
|
||||||
self.setup_channels()
|
self.setup_channels()
|
||||||
self.who_reqs = {}
|
|
||||||
|
# Locking
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self.channel_lock = False
|
self.channel_lock = False
|
||||||
self.channels = []
|
|
||||||
self.dict = {
|
|
||||||
"list": {},
|
|
||||||
"InitialProcess": False
|
|
||||||
}
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
# list of channels
|
||||||
''' will only get called for undefined attributes '''
|
self.chandict = {}
|
||||||
"""We will try to find a dict value, or return None"""
|
|
||||||
if name.lower() in list(self.dict.keys()):
|
# list of uuids to process
|
||||||
return self.dict[str(name).lower()]
|
self.server_recieved = []
|
||||||
|
|
||||||
|
# initial process
|
||||||
|
self.InitialProcess = False
|
||||||
|
|
||||||
|
self.who_reqs = {}
|
||||||
|
|
||||||
|
def total_channels(self):
|
||||||
|
totalcount = len(list(self.chandict.keys()))
|
||||||
|
return totalcount
|
||||||
|
|
||||||
|
def total_bot_channels(self):
|
||||||
|
totalcount = 0
|
||||||
|
for channel in list(self.chandict.keys()):
|
||||||
|
if self.chandict[channel]["joined"]:
|
||||||
|
totalcount += 1
|
||||||
|
return totalcount
|
||||||
|
|
||||||
|
def chanlist(self):
|
||||||
|
return list(self.chandict.keys())
|
||||||
|
|
||||||
|
def chanlist_bot(self):
|
||||||
|
chanlist_return = []
|
||||||
|
for channel in list(self.chandict.keys()):
|
||||||
|
if self.chandict[channel]["joined"]:
|
||||||
|
chanlist_return.append(channel)
|
||||||
|
return chanlist_return
|
||||||
|
|
||||||
|
def ischannel(self, channel):
|
||||||
|
|
||||||
|
# channel names case-sensitivity should never be an issue
|
||||||
|
channel = str(channel).lower()
|
||||||
|
|
||||||
|
if channel in list(self.chandict.keys()):
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
raise Exception('Channel dict does not contain a function or key ' + str(name.lower()))
|
return False
|
||||||
|
|
||||||
def get_channel_users(self, channel, idtype="nick"):
|
def get_channel_users(self, channel):
|
||||||
|
|
||||||
if channel.lower() not in list(self.dict["list"].keys()):
|
# channel names case-sensitivity should never be an issue
|
||||||
raise Exception('Channel ' + str(channel.lower()) + " does not seem to be on this server")
|
channel = str(channel).lower()
|
||||||
if 'users' not in list(self.dict["list"][channel.lower()].keys()) or not self.check_channel_bot(channel):
|
|
||||||
raise Exception('Channel ' + str(channel.lower()) + " does not seem to be a channel the bot is in")
|
|
||||||
|
|
||||||
nick_ids = self.dict["list"][channel.lower()]['users']
|
# channel not on server
|
||||||
if idtype.upper() == "ID":
|
if channel not in list(self.chandict.keys()):
|
||||||
return nick_ids
|
raise Exception('Channel ' + str(channel) + " does not seem to be on this server")
|
||||||
else:
|
|
||||||
nick_list = []
|
# bot is not in channel
|
||||||
for nick_id in nick_ids:
|
if not self.chandict[channel]["joined"]:
|
||||||
nickname = botusers.ID(nick_id)
|
raise Exception('Channel ' + str(channel) + " does not seem to be a channel the bot is in")
|
||||||
nick_list.append(nickname)
|
|
||||||
return nick_list
|
return self.chandict[channel]["users"]
|
||||||
|
|
||||||
def setup_channels(self):
|
def setup_channels(self):
|
||||||
botconfig.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
|
botconfig.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
|
||||||
@ -70,125 +102,169 @@ class BotChannels():
|
|||||||
self.channel_lock = True
|
self.channel_lock = True
|
||||||
|
|
||||||
def channel_list_recieve_input(self, trigger):
|
def channel_list_recieve_input(self, trigger):
|
||||||
self.lock.acquire()
|
|
||||||
|
# parse info
|
||||||
channel, _, topic = trigger.args[1:]
|
channel, _, topic = trigger.args[1:]
|
||||||
if channel.lower() not in list(self.dict['list'].keys()):
|
|
||||||
self.dict['list'][channel.lower()] = dict()
|
# check channel existance
|
||||||
self.dict['list'][channel.lower()]['name'] = channel
|
if channel not in list(self.chandict.keys()):
|
||||||
self.dict['list'][channel.lower()]['topic'] = self.topic_compile(topic)
|
self.channeldict_append(channel)
|
||||||
|
|
||||||
|
self.lock.acquire()
|
||||||
|
|
||||||
|
# get proper name of channel
|
||||||
|
self.chandict[channel.lower()]['name'] = channel
|
||||||
|
self.chandict[channel.lower()]['topic'] = self.topic_compile(topic)
|
||||||
self.channel_lock = True
|
self.channel_lock = True
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
def channel_list_recieve_finish(self):
|
def channel_list_recieve_finish(self):
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if not self.dict['InitialProcess']:
|
if not self.InitialProcess:
|
||||||
self.dict['InitialProcess'] = True
|
self.InitialProcess = True
|
||||||
self.lock.release()
|
|
||||||
self.channel_lock = False
|
self.channel_lock = False
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
def topic_compile(self, topic):
|
def topic_compile(self, topic):
|
||||||
actual_topic = re.compile(r'^\[\+[a-zA-Z]+\] (.*)')
|
actual_topic = re.compile(r'^\[\+[a-zA-Z]+\] (.*)')
|
||||||
topic = re.sub(actual_topic, r'\1', topic)
|
topic = re.sub(actual_topic, r'\1', topic)
|
||||||
|
if topic.isspace():
|
||||||
|
topic = None
|
||||||
return topic
|
return topic
|
||||||
|
|
||||||
def add_channel(self, channel):
|
def channeldict_append(self, channel):
|
||||||
|
|
||||||
|
# channel names case-sensitivity should never be an issue
|
||||||
channel = str(channel).lower()
|
channel = str(channel).lower()
|
||||||
|
|
||||||
|
# create basic components of the channel dict
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if channel not in self.channels:
|
if channel not in list(self.chandict.keys()):
|
||||||
self.channels.append(channel)
|
self.chandict[channel] = {
|
||||||
|
"name": channel,
|
||||||
|
"topic": None,
|
||||||
|
"joined": False,
|
||||||
|
"reason": "appended",
|
||||||
|
"users": [],
|
||||||
|
}
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
def remove_channel(self, channel):
|
def add_channel(self, channel, reason=None):
|
||||||
|
|
||||||
|
# channel names case-sensitivity should never be an issue
|
||||||
channel = str(channel).lower()
|
channel = str(channel).lower()
|
||||||
|
|
||||||
|
# check channel existance
|
||||||
|
if channel not in list(self.chandict.keys()):
|
||||||
|
self.channeldict_append(channel)
|
||||||
|
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if channel in self.channels:
|
self.chandict[channel]["joined"] = True
|
||||||
self.channels.remove(channel)
|
if reason != "check":
|
||||||
|
self.chandict[channel]["reason"] = reason
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
|
def remove_channel(self, channel, reason=None):
|
||||||
|
|
||||||
|
# channel names case-sensitivity should never be an issue
|
||||||
|
channel = str(channel).lower()
|
||||||
|
|
||||||
|
# check channel existance
|
||||||
|
if channel not in list(self.chandict.keys()):
|
||||||
|
self.channeldict_append(channel)
|
||||||
|
|
||||||
|
self.lock.acquire()
|
||||||
|
self.chandict[channel]["joined"] = False
|
||||||
|
if reason != "check":
|
||||||
|
self.chandict[channel]["reason"] = reason
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
def bot_part_empty(self, bot):
|
def bot_part_empty(self, bot):
|
||||||
"""Don't stay in empty channels"""
|
"""Don't stay in empty channels"""
|
||||||
ignorepartlist = []
|
ignorepartlist = [] # TODO add bot.config channels to ignore
|
||||||
if bot.config.core.logging_channel:
|
if bot.config.core.logging_channel:
|
||||||
ignorepartlist.append(bot.config.core.logging_channel)
|
ignorepartlist.append(bot.config.core.logging_channel)
|
||||||
for channel in list(bot.channels.keys()):
|
for channel in list(bot.channels.keys()):
|
||||||
if len(list(bot.channels[channel].privileges.keys())) == 1 and channel not in ignorepartlist and channel.startswith("#"):
|
if channel.startswith("#") and channel not in ignorepartlist:
|
||||||
|
if len(list(bot.channels[channel].privileges.keys())) == 1:
|
||||||
bot.part(channel, "Leaving Empty Channel")
|
bot.part(channel, "Leaving Empty Channel")
|
||||||
if channel.lower() in self.dict['list']:
|
if channel.lower() in list(self.chandict.keys()):
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
del self.dict['list'][channel.lower()]
|
self.chandict[channel]["joined"] = False
|
||||||
|
self.chandict[channel]["reason"] = "empty_chan_part"
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
self.remove_channel(channel)
|
self.remove_channel(channel)
|
||||||
|
|
||||||
def join_all_channels(self, bot):
|
def join_all_channels(self, bot):
|
||||||
if botconfig.SpiceBot_Channels.joinall:
|
if botconfig.SpiceBot_Channels.joinall:
|
||||||
for channel in list(self.dict['list'].keys()):
|
for channel in list(self.chandict.keys()):
|
||||||
if channel.startswith("#"):
|
if channel.startswith("#") and channel not in botconfig.SpiceBot_Channels.chanignore:
|
||||||
if channel not in list(bot.channels.keys()) and channel not in botconfig.SpiceBot_Channels.chanignore:
|
if channel.lower() not in [chan.lower() for chan in list(bot.channels.keys())]:
|
||||||
bot.write(('JOIN', bot.nick, self.dict['list'][channel]['name']))
|
self.bot_join(bot, channel)
|
||||||
if channel not in list(bot.channels.keys()) and botconfig.SpiceBot_Channels.operadmin:
|
if channel.lower() not in [chan.lower() for chan in list(bot.channels.keys())]:
|
||||||
bot.write(('SAJOIN', bot.nick, self.dict['list'][channel]['name']))
|
self.bot_sajoin(bot, channel)
|
||||||
|
|
||||||
if channel in list(bot.channels.keys()):
|
def bot_join(self, bot, channel):
|
||||||
self.add_channel(channel)
|
bot.write(('JOIN', bot.nick, channel))
|
||||||
|
|
||||||
def chanadmin_all_channels(self, bot):
|
def bot_sajoin(self, bot, channel):
|
||||||
|
if botconfig.SpiceBot_Channels.operadmin:
|
||||||
|
bot.write(('SAJOIN', bot.nick, channel))
|
||||||
|
|
||||||
|
def chanadmin_channel(self, bot, channel):
|
||||||
# Chan ADMIN +a
|
# Chan ADMIN +a
|
||||||
for channel in list(bot.channels.keys()):
|
|
||||||
if channel.startswith("#"):
|
|
||||||
self.add_channel(channel)
|
|
||||||
if channel not in botconfig.SpiceBot_Channels.chanignore:
|
|
||||||
if botconfig.SpiceBot_Channels.operadmin:
|
if botconfig.SpiceBot_Channels.operadmin:
|
||||||
if not bot.channels[channel].privileges[bot.nick] < sopel.module.ADMIN:
|
if not bot.channels[channel].privileges[bot.nick] < sopel.module.ADMIN:
|
||||||
bot.write(('SAMODE', channel, "+a", bot.nick))
|
bot.write(('SAMODE', channel, "+a", bot.nick))
|
||||||
else:
|
|
||||||
bot.part(channel)
|
|
||||||
|
|
||||||
if channel not in list(bot.channels.keys()):
|
|
||||||
self.remove_channel(channel)
|
|
||||||
|
|
||||||
def whois_ident(self, nick):
|
def whois_ident(self, nick):
|
||||||
nick = Identifier(nick)
|
nick = Identifier(nick)
|
||||||
nick_id = botdb.db.get_nick_id(nick, create=True)
|
nick_id = botusers.get_nick_id(nick, True)
|
||||||
return nick_id
|
return nick_id
|
||||||
|
|
||||||
def add_to_channel(self, channel, nick, nick_id=None):
|
def add_to_channel(self, channel, nick, nick_id=None):
|
||||||
|
|
||||||
|
# channel names case-sensitivity should never be an issue
|
||||||
channel = str(channel).lower()
|
channel = str(channel).lower()
|
||||||
|
|
||||||
|
# Verify Channel is in list
|
||||||
|
if channel not in list(self.chandict.keys()):
|
||||||
|
self.add_channel(channel, "error_handling")
|
||||||
|
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if not nick_id:
|
if not nick_id:
|
||||||
nick_id = self.whois_ident(nick)
|
nick_id = self.whois_ident(nick)
|
||||||
if channel.lower() not in list(self.dict['list'].keys()):
|
if int(nick_id) not in self.chandict[channel]["users"]:
|
||||||
self.dict['list'][channel.lower()] = dict()
|
self.chandict[channel]["users"].append(int(nick_id))
|
||||||
if 'users' not in self.dict['list'][channel.lower()]:
|
|
||||||
self.dict['list'][channel.lower()]['users'] = []
|
|
||||||
if int(nick_id) not in self.dict['list'][channel.lower()]['users']:
|
|
||||||
self.dict['list'][channel.lower()]['users'].append(int(nick_id))
|
|
||||||
if channel.lower() not in self.channels:
|
|
||||||
self.channels.append(channel.lower())
|
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
def remove_from_channel(self, channel, nick, nick_id=None):
|
def remove_from_channel(self, channel, nick, nick_id=None):
|
||||||
|
|
||||||
|
# channel names case-sensitivity should never be an issue
|
||||||
channel = str(channel).lower()
|
channel = str(channel).lower()
|
||||||
|
|
||||||
|
# Verify Channel is in list
|
||||||
|
if channel not in list(self.chandict.keys()):
|
||||||
|
self.add_channel(channel, "error_handling")
|
||||||
|
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if not nick_id:
|
if not nick_id:
|
||||||
nick_id = self.whois_ident(nick)
|
nick_id = self.whois_ident(nick)
|
||||||
if channel.lower() not in list(self.dict['list'].keys()):
|
if int(nick_id) in self.chandict[channel.lower()]['users']:
|
||||||
self.dict['list'][channel.lower()] = dict()
|
self.chandict[channel.lower()]['users'].remove(int(nick_id))
|
||||||
if 'users' not in self.dict['list'][channel.lower()]:
|
|
||||||
self.dict['list'][channel.lower()]['users'] = []
|
|
||||||
if int(nick_id) in self.dict['list'][channel.lower()]['users']:
|
|
||||||
self.dict['list'][channel.lower()]['users'].remove(int(nick_id))
|
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
def remove_all_from_channel(self, channel):
|
def remove_all_from_channel(self, channel):
|
||||||
|
|
||||||
|
# channel names case-sensitivity should never be an issue
|
||||||
channel = str(channel).lower()
|
channel = str(channel).lower()
|
||||||
|
|
||||||
|
# Verify Channel is in list
|
||||||
|
if channel not in list(self.chandict.keys()):
|
||||||
|
self.add_channel(channel, "error_handling")
|
||||||
|
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if channel.lower() not in list(self.dict['list'].keys()):
|
self.chandict[channel.lower()]['users'] = []
|
||||||
self.dict['list'][channel.lower()] = dict()
|
|
||||||
if 'users' not in self.dict['list'][channel.lower()]:
|
|
||||||
self.dict['list'][channel.lower()]['users'] = []
|
|
||||||
self.dict['list'][channel.lower()]['users'] = []
|
|
||||||
if channel.lower() in self.channels:
|
|
||||||
self.channels.remove(channel.lower())
|
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
def channel_scan(self, bot):
|
def channel_scan(self, bot):
|
||||||
@ -199,6 +275,7 @@ class BotChannels():
|
|||||||
def join(self, bot, trigger):
|
def join(self, bot, trigger):
|
||||||
# bot block
|
# bot block
|
||||||
if trigger.nick == bot.nick:
|
if trigger.nick == bot.nick:
|
||||||
|
self.chanadmin_channel(bot, trigger.sender)
|
||||||
for user in list(bot.channels[trigger.sender].privileges.keys()):
|
for user in list(bot.channels[trigger.sender].privileges.keys()):
|
||||||
self.add_to_channel(trigger.sender, user)
|
self.add_to_channel(trigger.sender, user)
|
||||||
return
|
return
|
||||||
@ -211,6 +288,10 @@ class BotChannels():
|
|||||||
# bot block
|
# bot block
|
||||||
if trigger.nick == bot.nick:
|
if trigger.nick == bot.nick:
|
||||||
self.remove_all_from_channel(trigger.sender)
|
self.remove_all_from_channel(trigger.sender)
|
||||||
|
self.lock.acquire()
|
||||||
|
self.chandict[trigger.sender]["joined"] = False
|
||||||
|
self.chandict[trigger.sender]["reason"] = "quit"
|
||||||
|
self.lock.release()
|
||||||
return
|
return
|
||||||
# Identify
|
# Identify
|
||||||
nick_id = self.whois_ident(trigger.nick)
|
nick_id = self.whois_ident(trigger.nick)
|
||||||
@ -221,6 +302,10 @@ class BotChannels():
|
|||||||
# bot block
|
# bot block
|
||||||
if trigger.nick == bot.nick:
|
if trigger.nick == bot.nick:
|
||||||
self.remove_all_from_channel(trigger.sender)
|
self.remove_all_from_channel(trigger.sender)
|
||||||
|
self.lock.acquire()
|
||||||
|
self.chandict[trigger.sender]["joined"] = False
|
||||||
|
self.chandict[trigger.sender]["reason"] = "bot_part"
|
||||||
|
self.lock.release()
|
||||||
return
|
return
|
||||||
# Identify
|
# Identify
|
||||||
nick_id = self.whois_ident(trigger.nick)
|
nick_id = self.whois_ident(trigger.nick)
|
||||||
@ -232,6 +317,10 @@ class BotChannels():
|
|||||||
# bot block
|
# bot block
|
||||||
if targetnick == bot.nick:
|
if targetnick == bot.nick:
|
||||||
self.remove_all_from_channel(trigger.sender)
|
self.remove_all_from_channel(trigger.sender)
|
||||||
|
self.lock.acquire()
|
||||||
|
self.chandict[trigger.sender]["joined"] = False
|
||||||
|
self.chandict[trigger.sender]["reason"] = "kicked"
|
||||||
|
self.lock.release()
|
||||||
return
|
return
|
||||||
# Identify
|
# Identify
|
||||||
nick_id = self.whois_ident(targetnick)
|
nick_id = self.whois_ident(targetnick)
|
||||||
@ -263,7 +352,7 @@ class BotChannels():
|
|||||||
if not channels:
|
if not channels:
|
||||||
return
|
return
|
||||||
channel = Identifier(channels.group(1))
|
channel = Identifier(channels.group(1))
|
||||||
self.add_channel(channel)
|
self.add_channel(channel, " check")
|
||||||
|
|
||||||
mapping = {'+': sopel.module.VOICE,
|
mapping = {'+': sopel.module.VOICE,
|
||||||
'%': sopel.module.HALFOP,
|
'%': sopel.module.HALFOP,
|
||||||
@ -287,9 +376,9 @@ class BotChannels():
|
|||||||
self.add_to_channel(channel, nick)
|
self.add_to_channel(channel, nick)
|
||||||
|
|
||||||
def check_channel_bot(self, channel, allchan=False):
|
def check_channel_bot(self, channel, allchan=False):
|
||||||
if str(channel).lower() in self.channels:
|
if str(channel).lower() in self.chanlist_bot():
|
||||||
return True
|
return True
|
||||||
elif allchan and str(channel).lower() in list(self.dict['list'].keys()):
|
elif allchan and str(channel).lower() in self.chanlist():
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|||||||
80
sopel_modules/SpiceBot/HTTP_Codes.py
Normal file
80
sopel_modules/SpiceBot/HTTP_Codes.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
# coding=utf8
|
||||||
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
|
"""
|
||||||
|
This is the SpiceBot HTTP Codes system.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
import requests
|
||||||
|
from lxml import html
|
||||||
|
|
||||||
|
|
||||||
|
class Bothttpcodes():
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.api_url = 'https://httpstatuses.com/'
|
||||||
|
self.basic_xpath = "/html/body/article/h1[1]/text()"
|
||||||
|
self.explain_xpath = "/html/body/article/p[1]/text()"
|
||||||
|
|
||||||
|
def fetch_result(self, query):
|
||||||
|
returndict = {
|
||||||
|
"basic": "",
|
||||||
|
"explanation": "",
|
||||||
|
}
|
||||||
|
if not re.match('^[1-5]\d{2}$', query):
|
||||||
|
returndict["basic"] = "Invalid HTTP status code:"
|
||||||
|
returndict["explanation"] = str(query)
|
||||||
|
return returndict
|
||||||
|
|
||||||
|
url = self.api_url + query
|
||||||
|
try:
|
||||||
|
r = requests.get(url=url, timeout=(10.0, 4.0))
|
||||||
|
except requests.exceptions.ConnectTimeout:
|
||||||
|
returndict["basic"] = "Connection timed out."
|
||||||
|
return returndict
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
returndict["basic"] = "Couldn't connect to server."
|
||||||
|
return returndict
|
||||||
|
except requests.exceptions.ReadTimeout:
|
||||||
|
returndict["basic"] = "Server took too long to send data."
|
||||||
|
return returndict
|
||||||
|
if r.status_code == 404:
|
||||||
|
returndict["basic"] = "Unknown HTTP status code:"
|
||||||
|
returndict["explanation"] = str(query)
|
||||||
|
return returndict
|
||||||
|
try:
|
||||||
|
r.raise_for_status()
|
||||||
|
except requests.exceptions.HTTPError as e:
|
||||||
|
returndict["basic"] = "HTTP error:"
|
||||||
|
returndict["explanation"] = str(e.message)
|
||||||
|
return returndict
|
||||||
|
|
||||||
|
tree = html.fromstring(r.content)
|
||||||
|
try:
|
||||||
|
title = tree.xpath((self.basic_xpath))
|
||||||
|
if isinstance(title, list):
|
||||||
|
title = title[0]
|
||||||
|
except Exception as e:
|
||||||
|
title = None
|
||||||
|
if title:
|
||||||
|
returndict["basic"] = str(title)
|
||||||
|
else:
|
||||||
|
returndict["basic"] = "An Error Occured:"
|
||||||
|
returndict["explanation"] = "Xpath for basic yeilded no information"
|
||||||
|
return returndict
|
||||||
|
|
||||||
|
try:
|
||||||
|
explanation = tree.xpath((self.explain_xpath))
|
||||||
|
if isinstance(explanation, list):
|
||||||
|
explanation = explanation[0]
|
||||||
|
except Exception as e:
|
||||||
|
explanation = None
|
||||||
|
if explanation:
|
||||||
|
returndict["explanation"] = str(explanation)
|
||||||
|
else:
|
||||||
|
returndict["explanation"] = "Xpath for explanation yeilded no information"
|
||||||
|
|
||||||
|
return returndict
|
||||||
|
|
||||||
|
|
||||||
|
httpcodes = Bothttpcodes()
|
||||||
@ -212,7 +212,7 @@ def verify_user(bot, trigger):
|
|||||||
|
|
||||||
|
|
||||||
def verify_channel(trigger):
|
def verify_channel(trigger):
|
||||||
botchannels.add_channel(trigger.sender)
|
botchannels.add_channel(trigger.sender, "check")
|
||||||
# Identify
|
# Identify
|
||||||
nick_id = botchannels.whois_ident(trigger.nick)
|
nick_id = botchannels.whois_ident(trigger.nick)
|
||||||
# Verify nick is in the channel list
|
# Verify nick is in the channel list
|
||||||
|
|||||||
@ -65,10 +65,19 @@ class BotUsers():
|
|||||||
nick_id = self.whois_ident(nickinput)
|
nick_id = self.whois_ident(nickinput)
|
||||||
return int(nick_id)
|
return int(nick_id)
|
||||||
|
|
||||||
|
def get_nick_id(self, nick, usercreate=True):
|
||||||
|
try:
|
||||||
|
nick_id = botdb.db.get_nick_id(nick, create=usercreate)
|
||||||
|
except Exception as e:
|
||||||
|
nick_id = e
|
||||||
|
nick_id = None
|
||||||
|
return None
|
||||||
|
return nick_id
|
||||||
|
|
||||||
def whois_ident(self, nick, usercreate=True):
|
def whois_ident(self, nick, usercreate=True):
|
||||||
nick = Identifier(nick)
|
nick = Identifier(nick)
|
||||||
try:
|
try:
|
||||||
nick_id = botdb.db.get_nick_id(nick, create=usercreate)
|
nick_id = self.get_nick_id(nick, usercreate)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
nick_id = e
|
nick_id = e
|
||||||
nick_id = None
|
nick_id = None
|
||||||
@ -267,6 +276,7 @@ class BotUsers():
|
|||||||
def nick(self, bot, trigger):
|
def nick(self, bot, trigger):
|
||||||
oldnick = trigger.nick
|
oldnick = trigger.nick
|
||||||
old_nick_id = self.whois_ident(oldnick)
|
old_nick_id = self.whois_ident(oldnick)
|
||||||
|
self.whois_identify_forget(old_nick_id)
|
||||||
newnick = Identifier(trigger)
|
newnick = Identifier(trigger)
|
||||||
if oldnick == bot.nick or newnick == bot.nick:
|
if oldnick == bot.nick or newnick == bot.nick:
|
||||||
return
|
return
|
||||||
@ -283,11 +293,11 @@ class BotUsers():
|
|||||||
# mark user as online
|
# mark user as online
|
||||||
self.mark_user_online(old_nick_id)
|
self.mark_user_online(old_nick_id)
|
||||||
# alias the nick
|
# alias the nick
|
||||||
try:
|
# try:
|
||||||
botdb.alias_nick(oldnick, newnick)
|
# botdb.alias_nick(oldnick, newnick)
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
old_nick_id = e
|
# old_nick_id = e
|
||||||
return
|
# return
|
||||||
|
|
||||||
def mode(self, bot, trigger):
|
def mode(self, bot, trigger):
|
||||||
return
|
return
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
# coding=utf8
|
# coding=utf8
|
||||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
"""
|
"""
|
||||||
This is the SpiceBot Update system.
|
This is the SpiceBot Version system.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sopel
|
import sopel
|
||||||
|
|||||||
@ -40,6 +40,7 @@ from .Translate import *
|
|||||||
from .Version import *
|
from .Version import *
|
||||||
from .RegNicks import *
|
from .RegNicks import *
|
||||||
from .ReleaseNotes import *
|
from .ReleaseNotes import *
|
||||||
|
from .HTTP_Codes import *
|
||||||
|
|
||||||
|
|
||||||
__author__ = 'Sam Zick'
|
__author__ = 'Sam Zick'
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
First release of Release Notes
|
First release of Release Notes
|
||||||
OSD updated to more accurately reflect IRC 512 byte limit
|
OSD updated to more accurately reflect IRC 512 byte limit
|
||||||
|
Channel Class cleaned up
|
||||||
|
|||||||
@ -0,0 +1,2 @@
|
|||||||
|
Added Tool to check HTTP code meanings, accessible via `.httpcodes` command
|
||||||
|
Migrated Functionality into a SpiceBot class for other tools to use
|
||||||
@ -22,23 +22,23 @@ def nickname_comand_channels(bot, trigger, botcom):
|
|||||||
botcom.dict['args'] = spicemanip(botcom.dict['args'], '2+', 'list')
|
botcom.dict['args'] = spicemanip(botcom.dict['args'], '2+', 'list')
|
||||||
|
|
||||||
if commandused == 'list':
|
if commandused == 'list':
|
||||||
botcount = len(list(bot.channels.keys()))
|
botcount = SpiceBot.channels.total_bot_channels()
|
||||||
servercount = len(list(SpiceBot.channels.dict['list'].keys()))
|
servercount = SpiceBot.channels.total_channels()
|
||||||
displayval = "I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server."
|
displayval = "I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server."
|
||||||
chanlist = spicemanip(list(bot.channels.keys()), 'andlist')
|
chanlist = spicemanip(SpiceBot.channels.chanlist_bot(), 'andlist')
|
||||||
bot.osd([displayval, "You can find me in " + chanlist])
|
bot.osd([displayval, "You can find me in " + chanlist])
|
||||||
return
|
return
|
||||||
|
|
||||||
elif commandused == 'total':
|
elif commandused == 'total':
|
||||||
botcount = len(list(bot.channels.keys()))
|
botcount = SpiceBot.channels.total_bot_channels()
|
||||||
servercount = len(list(SpiceBot.channels.dict['list'].keys()))
|
servercount = SpiceBot.channels.total_channels()
|
||||||
bot.osd("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.")
|
bot.osd("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.")
|
||||||
return
|
return
|
||||||
|
|
||||||
elif commandused == 'random':
|
elif commandused == 'random':
|
||||||
channel = spicemanip(SpiceBot.channels.dict['list'], 'random')
|
channel = spicemanip(list(SpiceBot.channels.chandict), 'random')
|
||||||
topic = SpiceBot.channels.dict['list'][channel]['topic']
|
topic = SpiceBot.channels.chandict[channel]['topic']
|
||||||
msg = ["Random channel for you: {}.".format(SpiceBot.channels.dict['list'][channel]['name'])]
|
msg = ["Random channel for you: {}.".format(SpiceBot.channels.chandict[channel]['name'])]
|
||||||
if topic and not topic.isspace():
|
if topic and not topic.isspace():
|
||||||
msg.append("The topic is: {}".format(topic))
|
msg.append("The topic is: {}".format(topic))
|
||||||
else:
|
else:
|
||||||
@ -47,7 +47,7 @@ def nickname_comand_channels(bot, trigger, botcom):
|
|||||||
return
|
return
|
||||||
|
|
||||||
elif commandused == 'update':
|
elif commandused == 'update':
|
||||||
if not trigger.admin:
|
if not trigger.admin: # TODO
|
||||||
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "You do not have permission to update the channel listing.")
|
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "You do not have permission to update the channel listing.")
|
||||||
return
|
return
|
||||||
SpiceBot.channels.bot_part_empty(bot)
|
SpiceBot.channels.bot_part_empty(bot)
|
||||||
@ -56,7 +56,7 @@ def nickname_comand_channels(bot, trigger, botcom):
|
|||||||
while SpiceBot.channels.channel_lock:
|
while SpiceBot.channels.channel_lock:
|
||||||
pass
|
pass
|
||||||
SpiceBot.channels.join_all_channels(bot)
|
SpiceBot.channels.join_all_channels(bot)
|
||||||
foundchannelcount = len(list(SpiceBot.channels.dict['list'].keys()))
|
foundchannelcount = len(list(SpiceBot.channels.chandict.keys()))
|
||||||
bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.")
|
bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.")
|
||||||
SpiceBot.channels.bot_part_empty(bot)
|
SpiceBot.channels.bot_part_empty(bot)
|
||||||
return
|
return
|
||||||
@ -66,12 +66,13 @@ def nickname_comand_channels(bot, trigger, botcom):
|
|||||||
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name input missing.")
|
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name input missing.")
|
||||||
return
|
return
|
||||||
channel = spicemanip(botcom.dict['args'], 1)
|
channel = spicemanip(botcom.dict['args'], 1)
|
||||||
if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())):
|
if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.chandict.keys())):
|
||||||
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel))
|
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel))
|
||||||
return
|
return
|
||||||
topic = SpiceBot.channels.dict['list'][channel.lower()]['topic']
|
channel = str(channel).lower()
|
||||||
channel = SpiceBot.channels.dict['list'][channel.lower()]['name']
|
topic = SpiceBot.channels.chandict[channel]['topic']
|
||||||
bot.osd("Topic for {}: {}".format(channel, topic))
|
channelname = SpiceBot.channels.chandict[channel]['name']
|
||||||
|
bot.osd("Topic for {}: {}".format(channelname, topic))
|
||||||
return
|
return
|
||||||
|
|
||||||
if commandused.upper() in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']:
|
if commandused.upper() in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']:
|
||||||
@ -83,7 +84,7 @@ def nickname_comand_channels(bot, trigger, botcom):
|
|||||||
channel = trigger.sender
|
channel = trigger.sender
|
||||||
else:
|
else:
|
||||||
channel = spicemanip(botcom.dict['args'], 1)
|
channel = spicemanip(botcom.dict['args'], 1)
|
||||||
if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())):
|
if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.chandict.keys())):
|
||||||
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel))
|
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel))
|
||||||
return
|
return
|
||||||
if not SpiceBot.inlist(channel.lower(), list(bot.channels.keys())):
|
if not SpiceBot.inlist(channel.lower(), list(bot.channels.keys())):
|
||||||
@ -103,7 +104,7 @@ def nickname_comand_channels(bot, trigger, botcom):
|
|||||||
# Users List
|
# Users List
|
||||||
if commandused == 'users':
|
if commandused == 'users':
|
||||||
channel = spicemanip(botcom.dict['args'], 1)
|
channel = spicemanip(botcom.dict['args'], 1)
|
||||||
if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.dict['list'].keys())):
|
if not SpiceBot.inlist(channel.lower(), list(SpiceBot.channels.chandict.keys())):
|
||||||
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel))
|
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel name {} not valid.".format(channel))
|
||||||
return
|
return
|
||||||
if not SpiceBot.inlist(channel.lower(), list(bot.channels.keys())):
|
if not SpiceBot.inlist(channel.lower(), list(bot.channels.keys())):
|
||||||
|
|||||||
@ -42,7 +42,7 @@ def bot_command_process(bot, trigger, botcom):
|
|||||||
|
|
||||||
target = spicemanip(botcom.dict['args'], 1)
|
target = spicemanip(botcom.dict['args'], 1)
|
||||||
if (target not in ['allchans', 'allnicks']
|
if (target not in ['allchans', 'allnicks']
|
||||||
and not SpiceBot.inlist(target.lower(), list(SpiceBot.channels.dict['list'].keys()))
|
and not SpiceBot.channels.ischannel(target)
|
||||||
and not SpiceBot.inlist(target.lower(), bot.users)):
|
and not SpiceBot.inlist(target.lower(), bot.users)):
|
||||||
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel/nick name {} not valid.".format(target))
|
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "Channel/nick name {} not valid.".format(target))
|
||||||
return
|
return
|
||||||
|
|||||||
@ -31,21 +31,17 @@ def request_channels_list_initial(bot, trigger):
|
|||||||
starttime = time.time()
|
starttime = time.time()
|
||||||
|
|
||||||
# wait 60 seconds for initial population of information
|
# wait 60 seconds for initial population of information
|
||||||
while not SpiceBot.channels.dict['InitialProcess']:
|
while not SpiceBot.channels.InitialProcess:
|
||||||
if time.time() - starttime >= 60:
|
if time.time() - starttime >= 60:
|
||||||
SpiceBot.logs.log('SpiceBot_Channels', "Initial Channel list populating Timed Out")
|
SpiceBot.logs.log('SpiceBot_Channels', "Initial Channel list populating Timed Out")
|
||||||
SpiceBot.channels.dict['InitialProcess'] = True
|
SpiceBot.channels.InitialProcess = True
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
foundchannelcount = len(list(SpiceBot.channels.dict['list'].keys()))
|
foundchannelcount = SpiceBot.channels.total_channels()
|
||||||
SpiceBot.logs.log('SpiceBot_Channels', "Channel listing finished! " + str(foundchannelcount) + " channel(s) found.")
|
SpiceBot.logs.log('SpiceBot_Channels', "Channel listing finished! " + str(foundchannelcount) + " channel(s) found.")
|
||||||
|
|
||||||
SpiceBot.channels.join_all_channels(bot)
|
SpiceBot.channels.join_all_channels(bot)
|
||||||
SpiceBot.channels.chanadmin_all_channels(bot)
|
|
||||||
|
|
||||||
if "*" in SpiceBot.channels.dict['list'].keys():
|
|
||||||
del SpiceBot.channels.dict['list']["*"]
|
|
||||||
|
|
||||||
SpiceBot.channels.bot_part_empty(bot)
|
SpiceBot.channels.bot_part_empty(bot)
|
||||||
SpiceBot.events.trigger(bot, SpiceBot.events.BOT_CHANNELS, "SpiceBot_Channels")
|
SpiceBot.events.trigger(bot, SpiceBot.events.BOT_CHANNELS, "SpiceBot_Channels")
|
||||||
@ -76,13 +72,17 @@ def trigger_channel_list_recurring(bot, trigger):
|
|||||||
time.sleep(1800)
|
time.sleep(1800)
|
||||||
SpiceBot.channels.bot_part_empty(bot)
|
SpiceBot.channels.bot_part_empty(bot)
|
||||||
|
|
||||||
oldlist = list(SpiceBot.channels.dict['list'].keys())
|
oldlist = SpiceBot.channels.chanlist()
|
||||||
SpiceBot.channels.channel_list_request(bot)
|
SpiceBot.channels.channel_list_request(bot)
|
||||||
|
|
||||||
while SpiceBot.channels.channel_lock:
|
while SpiceBot.channels.channel_lock:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
newlist = [item.lower() for item in oldlist if item.lower() not in list(SpiceBot.channels.dict['list'].keys())]
|
currentlist = SpiceBot.channels.chanlist()
|
||||||
|
newlist = []
|
||||||
|
for channel in currentlist:
|
||||||
|
if channel not in oldlist:
|
||||||
|
newlist.append(channel)
|
||||||
if "*" in newlist:
|
if "*" in newlist:
|
||||||
newlist.remove("*")
|
newlist.remove("*")
|
||||||
if len(newlist) and SpiceBot.config.SpiceBot_Channels.announcenew:
|
if len(newlist) and SpiceBot.config.SpiceBot_Channels.announcenew:
|
||||||
@ -90,10 +90,6 @@ def trigger_channel_list_recurring(bot, trigger):
|
|||||||
|
|
||||||
SpiceBot.channels.join_all_channels(bot)
|
SpiceBot.channels.join_all_channels(bot)
|
||||||
|
|
||||||
SpiceBot.channels.chanadmin_all_channels(bot)
|
|
||||||
|
|
||||||
if "*" in list(SpiceBot.channels.dict['list'].keys()):
|
|
||||||
del SpiceBot.channels.dict['list']["*"]
|
|
||||||
SpiceBot.channels.bot_part_empty(bot)
|
SpiceBot.channels.bot_part_empty(bot)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -30,8 +30,8 @@ def bot_startup_monologue_sopel_version(bot, trigger):
|
|||||||
@sopel.module.event(SpiceBot.events.BOT_CHANNELS)
|
@sopel.module.event(SpiceBot.events.BOT_CHANNELS)
|
||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def bot_startup_monologue_channels(bot, trigger):
|
def bot_startup_monologue_channels(bot, trigger):
|
||||||
botcount = len(list(bot.channels.keys()))
|
botcount = SpiceBot.channels.total_bot_channels()
|
||||||
servercount = len(list(SpiceBot.channels.dict['list'].keys()))
|
servercount = SpiceBot.channels.total_channels()
|
||||||
displayval = "I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server."
|
displayval = "I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server."
|
||||||
SpiceBot.startupmonologue.dict["channels"] = displayval
|
SpiceBot.startupmonologue.dict["channels"] = displayval
|
||||||
SpiceBot.logs.log('SpiceBot_StartupMonologue', displayval)
|
SpiceBot.logs.log('SpiceBot_StartupMonologue', displayval)
|
||||||
|
|||||||
21
sopel_modules/SpiceBot_Core_Tools/HTTP_Codes.py
Normal file
21
sopel_modules/SpiceBot_Core_Tools/HTTP_Codes.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# coding=utf8
|
||||||
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
|
|
||||||
|
# sopel imports
|
||||||
|
import sopel.module
|
||||||
|
|
||||||
|
from sopel_modules.spicemanip import spicemanip
|
||||||
|
|
||||||
|
import sopel_modules.SpiceBot as SpiceBot
|
||||||
|
|
||||||
|
|
||||||
|
@SpiceBot.prerun('module')
|
||||||
|
@sopel.module.commands('httpcode')
|
||||||
|
def bot_command_http_codes(bot, trigger, botcom):
|
||||||
|
query = spicemanip(botcom.dict["args"], 1) or None
|
||||||
|
if not query:
|
||||||
|
return bot.osd("You must provide a HTTP status code to look up.")
|
||||||
|
message = ["[HTTP code search for " + str(query) + "]"]
|
||||||
|
result = SpiceBot.httpcodes.fetch_result(str(query))
|
||||||
|
message.extend([result["basic"], result["explanation"]])
|
||||||
|
bot.osd(message)
|
||||||
@ -6,6 +6,7 @@ from .Gif import *
|
|||||||
from .Sherlock import *
|
from .Sherlock import *
|
||||||
from .Reddit import *
|
from .Reddit import *
|
||||||
from .Search import *
|
from .Search import *
|
||||||
|
from .HTTP_Codes import *
|
||||||
|
|
||||||
__author__ = 'Sam Zick'
|
__author__ = 'Sam Zick'
|
||||||
__email__ = 'sam@deathbybandaid.net'
|
__email__ = 'sam@deathbybandaid.net'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user