Compare commits

..

No commits in common. "89bbecbf7af73cb588e59cfd72ff07e96b45e885" and "6e808e2510577d89ad14588c93e27215c8c75fb4" have entirely different histories.

8 changed files with 29 additions and 92 deletions

View file

@ -8,7 +8,7 @@ server {
location / {
proxy_pass http://[::1]:5001;
proxy_set_header Host $host:$server_port;
proxy_set_header Host $host:$port;
proxy_set_header X-Forwarded-For $remote_addr;
}
}

View file

@ -15,8 +15,8 @@ class Module(ModuleManager.BaseModule):
today = datetime.datetime.utcnow().date()
week = datetime.timedelta(days=7)
not_valid_until = (today-certificate.not_valid_before_utc.date()).days
not_valid_after = (certificate.not_valid_after_utc.date()-today).days
not_valid_until = (today-certificate.not_valid_before.date()).days
not_valid_after = (certificate.not_valid_after.date()-today).days
if not_valid_until < 0:
self.log.warn(

View file

@ -1,7 +1,7 @@
#--depends-on config
#--depends-on shorturl
import difflib, hashlib, time, re
import difflib, hashlib, time
from src import ModuleManager, utils
import feedparser
@ -13,39 +13,22 @@ SETTING_BIND = utils.Setting("rss-bindhost",
"Interval (in seconds) between RSS polls", example="120"))
@utils.export("channelset", utils.BoolSetting("rss-shorten",
"Whether or not to shorten RSS urls"))
@utils.export("channelset", utils.Setting("rss-format", "Format of RSS announcements", example="${longtitle}: ${title} - ${link} [${author}]"))
@utils.export("channelset", utils.Setting("rss-format", "Format of RSS announcements", example="$longtitle: $title - $link [$author]"))
@utils.export("serverset", SETTING_BIND)
@utils.export("channelset", SETTING_BIND)
class Module(ModuleManager.BaseModule):
_name = "RSS"
def _migrate_formats(self):
count = 0
migration_re = re.compile(r"(?:\$|{)+(?P<variable>[^}:\s]+)(?:})?")
old_formats = self.bot.database.execute_fetchall("""
SELECT channel_id, value FROM channel_settings
WHERE setting = 'rss-format'
""")
for channel_id, format in old_formats:
new_format = migration_re.sub(r"${\1}", format)
self.bot.database.execute("""
UPDATE channel_settings SET value = ?
WHERE setting = 'rss-format'
AND channel_id = ?
""", [new_format, channel_id])
count += 1
self.log.info("Successfully migrated %d rss-format settings" % count)
def on_load(self):
if not self.bot.get_setting("rss-fmt-migration", False):
self.log.info("Attempting to migrate old rss-format settings")
self._migrate_formats()
self.bot.set_setting("rss-fmt-migration", True)
self.timers.add("rss-feeds", self._timer,
self.bot.get_setting("rss-interval", RSS_INTERVAL))
def _format_entry(self, server, channel, feed_title, entry, shorten):
title = utils.parse.line_normalise(utils.http.strip_html(
entry["title"]))
author = entry.get("author", "unknown author")
author = "%s" % author if author else ""
link = entry.get("link", None)
if shorten:
try:
@ -54,21 +37,16 @@ class Module(ModuleManager.BaseModule):
pass
link = "%s" % link if link else ""
variables = dict(
longtitle=feed_title or "",
title=utils.parse.line_normalise(utils.http.strip_html(
entry["title"])),
link=link or "",
author=entry.get("author", "unknown author") or "",
)
variables.update(entry)
feed_title_str = "%s" % feed_title if feed_title else ""
# just in case the format starts keyerroring and you're not sure why
self.log.trace("RSS Entry: " + str(entry))
template = channel.get_setting("rss-format", "${longtitle}: ${title} by ${author} - ${link}")
_, formatted = utils.parse.format_token_replace(template, variables)
return formatted
try:
format = channel.get_setting("rss-format", "$longtitle: $title by $author - $link").replace("$longtitle", feed_title_str).replace("$title", title).replace("$link", link).replace("$author", author).format(**entry)
except KeyError:
self.log.warn(f"Failed to format RSS entry for {channel}. Falling back to default format.")
format = f"{feed_title_str}: {title} by {author} - {link}"
return format
def _timer(self, timer):
start_time = time.monotonic()

View file

@ -32,7 +32,7 @@ class Module(ModuleManager.BaseModule):
for pod in page["queryresult"]["pods"]:
text = pod["subpods"][0]["plaintext"]
if pod["id"] == "Input" and text:
input = text.replace("\n", " | ")
input = text
elif pod.get("primary", False):
primaries.append(text)

View file

@ -10,7 +10,8 @@ netifaces ==0.10.9
PySocks ==1.7.1
python-dateutil ==2.8.1
pytz ==2019.2
requests ==2.31.0
tornado ==6.3.2
requests ==2.22.0
suds ==1.0.0
tornado ==6.0.3
tweepy ==3.8.0
requests-toolbelt ==0.9.1

View file

@ -235,7 +235,7 @@ class ModuleManager(object):
definition.filename)
module = importlib.util.module_from_spec(import_spec)
sys.modules[import_name] = module
loader = typing.cast(importlib._abc.Loader, import_spec.loader)
loader = typing.cast(importlib.abc.Loader, import_spec.loader)
loader.exec_module(module)
module_object_pointer = getattr(module, "Module", None)

View file

@ -12,23 +12,12 @@ class Module(ModuleManager.BaseModule):
return channel.get_user_setting(user.get_id(), "ignore", False)
def _server_command_ignored(self, server, command):
return server.get_setting("ignore-%s" % command, False)
def _channel_command_ignored(self, channel, command):
return channel.get_setting("ignore-command-%s" % command, False)
def _is_command_ignored(self, event):
if self._user_command_ignored(event["user"], event["command"]):
def _is_command_ignored(self, server, user, command):
if self._user_command_ignored(user, command):
return True
elif self._server_command_ignored(event["server"], event["command"]):
elif self._server_command_ignored(server, command):
return True
elif event["is_channel"] and self._channel_command_ignored(event["target"], event["command"]):
return True
def _is_valid_command(self, command):
hooks = self.events.on("received.command").on(command).get_hooks()
if hooks:
return True
else:
return False
@utils.hook("received.message.private")
@utils.hook("received.message.channel")
@ -49,7 +38,8 @@ class Module(ModuleManager.BaseModule):
elif event["is_channel"] and self._user_channel_ignored(event["target"],
event["user"]):
return utils.consts.PERMISSION_HARD_FAIL, None
elif self._is_command_ignored(event):
elif self._is_command_ignored(event["server"], event["user"],
event["command"]):
return utils.consts.PERMISSION_HARD_FAIL, None
@utils.hook("received.command.ignore", min_args=1)
@ -133,38 +123,6 @@ class Module(ModuleManager.BaseModule):
True)
event["stdout"].write("Ignoring %s" % target_user.nickname)
@utils.hook("received.command.ignorecommand",
help="Ignore a command in this channel")
@utils.hook("received.command.unignorecommand",
help="Unignore a command in this channel")
@utils.kwarg("channel_only", True)
@utils.kwarg("min_args", 1)
@utils.kwarg("usage", "<command>")
@utils.kwarg("permission", "cignore")
@utils.kwarg("require_mode", "o")
@utils.kwarg("require_access", "high,cignore")
def cignore_command(self, event):
remove = event["command"] == "unignorecommand"
command = event["args_split"][0]
if not self._is_valid_command(command):
raise utils.EventError("Unknown command '%s'" % command)
is_ignored = self._channel_command_ignored(event["target"], command)
if remove:
if not is_ignored:
raise utils.EventError("I'm not ignoring '%s' in this channel" %
target_user.nickname)
event["target"].del_setting("ignore-command-%s" % command)
event["stdout"].write("Unignored '%s' command" % command)
else:
if is_ignored:
raise utils.EventError("I'm already ignoring '%s' in this channel"
% command)
event["target"].set_setting("ignore-command-%s" % command, True)
event["stdout"].write("Ignoring '%s' command" % command)
@utils.hook("received.command.serverignore")
@utils.kwarg("help", "Ignore a command on the current server")
@utils.kwarg("permission", "serverignore")

View file

@ -304,7 +304,7 @@ def request_many(requests: typing.List[Request]) -> typing.Dict[str, Response]:
loop = asyncio.new_event_loop()
awaits = []
for request in requests:
awaits.append(loop.create_task(_request(request)))
awaits.append(_request(request))
task = asyncio.wait(awaits, timeout=5)
loop.run_until_complete(task)
loop.close()