This commit is contained in:
deathbybandaid 2019-06-07 13:10:15 -04:00
parent f2d4307bfc
commit 94964aadc0
8 changed files with 203 additions and 19 deletions

View File

@ -0,0 +1,107 @@
# coding=utf8
from __future__ import unicode_literals, absolute_import, division, print_function
"""A way to track users"""
from sopel.tools import Identifier
from .Database import db as botdb
from .Tools import inlist, inlist_match
class BotUsers():
def __init__(self):
self.all = botdb.get_bot_value('users') or []
self.online = []
self.save_user_db()
def whois(self, nick):
nick = Identifier(nick)
nick_id = botdb.db.get_nick_id(nick, create=True)
return nick_id
def save_user_db(self):
botdb.set_bot_value('users', self.all)
def join(self, bot, trigger):
# bot block
if trigger.nick == bot.nick:
return
# Identify
nick_id = self.whois(trigger.nick)
# mark online
self.mark_online(trigger.nick, nick_id)
def quit(self, bot, trigger):
# bot block
if trigger.nick == bot.nick:
return
# Identify
nick_id = self.whois(trigger.nick)
# mark offline
self.mark_offline(trigger.nick, nick_id)
def part(self, bot, trigger):
# bot block
if trigger.nick == bot.nick:
return
# Identify
nick_id = self.whois(trigger.nick)
# mark offline
if trigger.nick not in bot.users:
self.mark_offline(trigger.nick, nick_id)
def kick(self, bot, trigger):
target = str(trigger.args[1])
# bot block
if target == bot.nick:
return
# Identify
nick_id = self.whois(target)
# mark offline
if target not in bot.users:
self.mark_offline(target, nick_id)
def add_to_all(self, nick, nick_id=None):
if not nick_id:
nick_id = self.whois(nick)
# add to all if not there
if nick_id not in self.all.keys():
self.all[nick_id] = {"aliases": []}
# add nick alias
if nick not in self.all[nick_id]:
self.all[nick_id]["aliases"].append(nick)
def mark_online(self, nick, nick_id=None):
if not nick_id:
nick_id = self.whois(nick)
self.add_to_all(nick, nick_id)
if nick_id not in self.online:
self.online.append(nick_id)
def mark_offline(self, nick, nick_id=None):
if not nick_id:
nick_id = self.whois(nick)
self.add_to_all(nick, nick_id)
if nick_id in self.online:
self.online.remove(nick_id)
def current(self, bot, reqchannel='all'):
user_list = []
if reqchannel == 'all':
for channel in bot.channels.keys():
for user in bot.channels[channel].privileges.keys():
user_id = self.whois(user)
user_list.append(user_id)
return user_list
elif not inlist(reqchannel, bot.channels.keys()):
return user_list
else:
channel = inlist_match(reqchannel, bot.channels.keys())
for user in bot.channels[channel].privileges.keys():
user_id = self.whois(user)
user_list.append(user_id)
return user_list
users = BotUsers()

View File

@ -20,6 +20,7 @@ from .Commands import *
from .Events import *
from .StartupMonologue import *
from .Channels import *
from .Users import *
from .AI import *

View File

@ -87,22 +87,3 @@ def bot_command_nick(bot, trigger):
else:
bot.osd("I'm afraid you do not have the authority to make that call, " + trigger.nick + ".")
return
elif fulltrigger.lower().startswith("can you see"):
target = spicemanip.main(trigger.sb['args'], "4+") or None
if not target:
bot.osd(trigger.nick + ", I can see clearly.")
return
if target in [trigger.nick, 'me']:
bot.osd(trigger.nick + ", I can see you.")
else:
if SpiceBot.inlist(trigger.nick, bot.users):
bot.osd(trigger.nick + ", yes. I can see " + SpiceBot.inlist_match(target, bot.users) + " right now!")
else:
bot.osd(trigger.nick + ", no. I cannot see " + SpiceBot.inlist_match(target, bot.users) + " right now!")
# if bot_check_inlist(target, bot.memory["botdict"]["users"].keys()):
# bot.osd(trigger.nick + ", I can't see " + inlist_match(target, bot.users) + " at the moment.")
# else:
# bot.osd("I have never seen " + str(target) + ".")
# TODO
return

View File

@ -83,6 +83,28 @@ def bot_command_rule(bot, trigger):
bot.osd(str(searchreturn))
return
elif trigger_args[0].lower() in ["can"] and trigger_args[1].lower() in ["you"] and trigger_args[2].lower() in ["see"]:
target = spicemanip.main(trigger_args, "4+") or None
if target:
if SpiceBot.inlist(trigger.nick, bot.users):
realtarget = SpiceBot.inlist_match(target, bot.users)
dispmsg = [trigger.nick + ", yes. I can see " + realtarget]
targetchannels = []
for channel in bot.channels.keys():
if SpiceBot.inlist(trigger.nick, bot.channels[channel].privileges.keys()):
targetchannels.append(channel)
dispmsg.append(realtarget + " is in " + spicemanip.main(targetchannels, 'andlist'))
bot.osd(dispmsg)
else:
bot.osd(trigger.nick + ", no. I cannot see " + target + " right now!")
# if bot_check_inlist(target, bot.memory["botdict"]["users"].keys()):
# bot.osd(trigger.nick + ", I can't see " + inlist_match(target, bot.users) + " at the moment.")
# else:
# bot.osd("I have never seen " + str(target) + ".")
# user in bot.channels[channel].privileges.keys()
# TODO
return
closestmatches = SpiceBot.similar_list(trigger_command, SpiceBot.commands.dict['commands']["nickname"].keys(), 3, 'reverse')
if len(closestmatches):
closestmatches = spicemanip.main(closestmatches, "andlist")

View File

@ -22,4 +22,24 @@
</template>
</category>
<category>
<pattern>BOTNICK you there</pattern>
<template>
<random>
<li>Need something, triggernick?</li>
<li>What's going on, triggernick?</li>
</random>
</template>
</category>
<category>
<pattern>you there BOTNICK</pattern>
<template>
<random>
<li>Need something, triggernick?</li>
<li>What's going on, triggernick?</li>
</random>
</template>
</category>
</aiml>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0">
<category>
<pattern>BOTNICK can you see me</pattern>
<template>triggernick, I can see you.</template>
</category>
<category>
<pattern>BOTNICK can you see</pattern>
<template>triggernick, I can see clearly.</template>
</category>
</aiml>

View File

@ -8,6 +8,7 @@ This module contains references only for other modules to utilize.
from .CommandsQuery import *
from .Commands import *
from .Users import *
from .Channels import *
from .Database import *
from .Uptime import *

View File

@ -0,0 +1,36 @@
# coding=utf8
from __future__ import unicode_literals, absolute_import, division, print_function
"""
This is the SpiceBot Channels system.
"""
import sopel
import sopel_modules.SpiceBot as SpiceBot
@sopel.module.event('JOIN')
@sopel.module.rule('.*')
def users_join(bot, trigger):
bot.say(str(trigger.args))
# SpiceBot.users.join(bot, trigger)
@sopel.module.event('QUIT')
@sopel.module.rule('.*')
def users_quit(bot, trigger):
bot.say(str(trigger.args))
# SpiceBot.users.quit(bot, trigger)
@sopel.module.event('PART')
@sopel.module.rule('.*')
def users_part(bot, trigger):
bot.say(str(trigger.args))
# SpiceBot.users.part(bot, trigger)
@sopel.module.event('KICK')
@sopel.module.rule('.*')
def users_kick(bot, trigger):
bot.say(str(trigger.args))
# SpiceBot.users.kick(bot, trigger)