add ignorelist for spammers, remove idle-loop
This commit is contained in:
11
idlebot.py
11
idlebot.py
@@ -97,17 +97,6 @@ def start(botclass, active=False):
|
|||||||
|
|
||||||
config.runtimeconf_set('start_time', -time.time())
|
config.runtimeconf_set('start_time', -time.time())
|
||||||
|
|
||||||
while 1:
|
|
||||||
try:
|
|
||||||
# print("hangup: %s" % got_hangup)
|
|
||||||
if not plugins.event_trigger():
|
|
||||||
bot.hangup()
|
|
||||||
|
|
||||||
time.sleep(EVENTLOOP_DELAY)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print('')
|
|
||||||
exit(130)
|
|
||||||
|
|
||||||
|
|
||||||
if '__main__' == __name__:
|
if '__main__' == __name__:
|
||||||
start(IdleBot)
|
start(IdleBot)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
other_bots = string_list(default=list())
|
other_bots = string_list(default=list())
|
||||||
|
spammers = string_list(default=list())
|
||||||
request_counter = integer(default=0)
|
request_counter = integer(default=0)
|
||||||
start_time = integer(default=0)
|
start_time = integer(default=0)
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ import unicodedata
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import config
|
import config
|
||||||
from common import VERSION, RATE_FUN, RATE_GLOBAL, RATE_INTERACTIVE, RATE_NO_LIMIT, giphy, BUFSIZ, pluginfunction, \
|
from common import (
|
||||||
|
VERSION, RATE_FUN, RATE_GLOBAL, RATE_INTERACTIVE, RATE_NO_LIMIT, BUFSIZ,
|
||||||
|
giphy, pluginfunction,
|
||||||
ptypes_COMMAND
|
ptypes_COMMAND
|
||||||
from plugins import ptypes_COMMAND
|
)
|
||||||
from string_constants import cakes, excuses, moin_strings_hi, moin_strings_bye
|
from string_constants import cakes, excuses, moin_strings_hi, moin_strings_bye
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@@ -664,6 +666,8 @@ def command_show_recordlist(argv, **args):
|
|||||||
# msg = 'wrong argument'
|
# msg = 'wrong argument'
|
||||||
# log.warn(msg)
|
# log.warn(msg)
|
||||||
# return {'msg': msg}
|
# return {'msg': msg}
|
||||||
|
|
||||||
|
|
||||||
@pluginfunction("provoke-bots", "search for other bots", ptypes_COMMAND)
|
@pluginfunction("provoke-bots", "search for other bots", ptypes_COMMAND)
|
||||||
def provoke_bots(argv, **args):
|
def provoke_bots(argv, **args):
|
||||||
if 'provoke-bots' == argv[0]:
|
if 'provoke-bots' == argv[0]:
|
||||||
@@ -759,3 +763,33 @@ def reload_runtimeconfig(argv, **args):
|
|||||||
else:
|
else:
|
||||||
config.runtime_config_store.reload()
|
config.runtime_config_store.reload()
|
||||||
return {'msg': 'done'}
|
return {'msg': 'done'}
|
||||||
|
|
||||||
|
|
||||||
|
@pluginfunction('snitch', "tell on a spammy user", ptypes_COMMAND)
|
||||||
|
def ignore_user(argv, **args):
|
||||||
|
if len(argv) != 2:
|
||||||
|
return {'msg': 'syntax: "{}: snitch username"'.format(config.conf_get("bot_nickname"))}
|
||||||
|
|
||||||
|
then = time.time() + 15*60
|
||||||
|
spammer = argv[1]
|
||||||
|
|
||||||
|
if spammer not in config.runtime_config_store['spammers']:
|
||||||
|
config.runtime_config_store['spammers'].append(spammer)
|
||||||
|
|
||||||
|
def unblock_user(user):
|
||||||
|
if user not in config.runtime_config_store['spammers']:
|
||||||
|
config.runtime_config_store['spammers'].append(user)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'msg': 'user reported and ignored till {}'.format(time.strftime('%H:%M', time.localtime(then))),
|
||||||
|
'event': {
|
||||||
|
'time': then,
|
||||||
|
'command': (unblock_user, ([spammer],))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pluginfunction('raise', 'only for debugging', ptypes_COMMAND)
|
||||||
|
def raise_an_error(argv, **args):
|
||||||
|
if args['reply_user'] == config.conf_get("bot_owner"):
|
||||||
|
raise RuntimeError("Exception for debugging")
|
||||||
|
|||||||
16
urlbot.py
16
urlbot.py
@@ -43,6 +43,7 @@ class UrlBot(IdleBot):
|
|||||||
|
|
||||||
for room in self.rooms:
|
for room in self.rooms:
|
||||||
self.add_event_handler('muc::%s::got_online' % room, self.muc_online)
|
self.add_event_handler('muc::%s::got_online' % room, self.muc_online)
|
||||||
|
self.add_event_handler('muc::%s::got_offline' % room, self.muc_offline)
|
||||||
|
|
||||||
def muc_message(self, msg_obj):
|
def muc_message(self, msg_obj):
|
||||||
"""
|
"""
|
||||||
@@ -106,6 +107,17 @@ class UrlBot(IdleBot):
|
|||||||
|
|
||||||
config.conf_set('persistent_locked', False)
|
config.conf_set('persistent_locked', False)
|
||||||
|
|
||||||
|
def muc_offline(self, msg_obj):
|
||||||
|
room = msg_obj.values['muc']['room']
|
||||||
|
user = msg_obj.values['muc']['nick']
|
||||||
|
if user == config.conf_get('bot_nickname'):
|
||||||
|
self.logger.warn("Left my room, rejoin")
|
||||||
|
self.plugin['xep_0045'].joinMUC(
|
||||||
|
room,
|
||||||
|
self.nick,
|
||||||
|
wait=True
|
||||||
|
)
|
||||||
|
|
||||||
# @rate_limited(10)
|
# @rate_limited(10)
|
||||||
def send_reply(self, message, msg_obj=None):
|
def send_reply(self, message, msg_obj=None):
|
||||||
"""
|
"""
|
||||||
@@ -199,6 +211,10 @@ class UrlBot(IdleBot):
|
|||||||
self.logger.info('no spoiler for: ' + content)
|
self.logger.info('no spoiler for: ' + content)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if msg_obj['mucnick'] in config.runtime_config_store['spammers']:
|
||||||
|
self.logger.info("ignoring spammer {}".format(msg_obj['mucnick']))
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.data_parse_commands(msg_obj)
|
self.data_parse_commands(msg_obj)
|
||||||
self.data_parse_other(msg_obj)
|
self.data_parse_other(msg_obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user