Add database.find_by_setting, send github commits to interested channels
This commit is contained in:
parent
4296d1ee8e
commit
df94020ef5
2 changed files with 28 additions and 3 deletions
|
@ -1,6 +1,9 @@
|
|||
import json
|
||||
from src import ModuleManager, utils
|
||||
|
||||
@utils.export("channelset", {"setting": "github-hook",
|
||||
"help": ("Disable/Enable showing BitBot's github commits in the "
|
||||
"current channel"), "validate": utils.bool_or_none})
|
||||
class Module(ModuleManager.BaseModule):
|
||||
@utils.hook("api.post.github")
|
||||
def github(self, event):
|
||||
|
@ -22,6 +25,15 @@ class Module(ModuleManager.BaseModule):
|
|||
added_count = len(commit["added"])
|
||||
removed_count = len(commit["removed"])
|
||||
|
||||
print("(%s) [%d/%d/%d mod/add/del] commit by %s: %s" % (
|
||||
full_name, modified_count, added_count, removed_count,
|
||||
author, message))
|
||||
line = ("(%s) [files: %d/%d/%d mod/add/del] commit by %s: "
|
||||
"'%s'") % (full_name, modified_count, added_count,
|
||||
removed_count, author, message)
|
||||
hooks = self.bot.database.channel_settings.find_by_setting(
|
||||
"github-hook")
|
||||
hooks = [hook for hook in hooks if hook[2]]
|
||||
for server_id, channel_name, _ in hooks:
|
||||
server = self.bot.get_server(server_id)
|
||||
channel = server.get_channel(channel_name)
|
||||
|
||||
self.events.on("send.stdout").call(target=channel,
|
||||
module_name="Github", server=server, message=line)
|
||||
|
|
|
@ -140,6 +140,19 @@ class ChannelSettings(Table):
|
|||
"""DELETE FROM channel_settings WHERE channel_id=?
|
||||
AND setting=?""", [channel_id, setting.lower()])
|
||||
|
||||
def find_by_setting(self, setting, default=[]):
|
||||
values = self.database.execute_fetchall(
|
||||
"""SELECT channels.server_id, channels.name,
|
||||
channel_settings.value FROM channel_settings
|
||||
INNER JOIN channels ON
|
||||
channel_settings.channel_id=channels.channel_id
|
||||
WHERE channel_settings.setting=?""", [setting])
|
||||
if values:
|
||||
for i, value in enumerate(values):
|
||||
values[i] = value[0], value[1], json.loads(value[2])
|
||||
return values
|
||||
return default
|
||||
|
||||
class UserSettings(Table):
|
||||
def set(self, user_id, setting, value):
|
||||
self.database.execute(
|
||||
|
|
Loading…
Reference in a new issue