async def sweep_trash(self, user): await asyncio.sleep( Configuration.get_var("bug_trash_sweep_minutes") * 60) if user.id in self.in_progress: if not self.in_progress[user.id].done() or not self.in_progress[ user.id].cancelled(): await user.send(Lang.get_string("bugs/sweep_trash")) await self.delete_progress(user.id)
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["mysql"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files) process_assert(publish_future(context, conf))
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["hosts"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files) archive.tar_archive(context, conf)
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["mysql"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files) start_http_server(context, conf)
async def remove(self, ctx: commands.Context, roleraw): """Used to remove roles from the joinable list""" role_list = Configuration.getConfigVar(ctx.guild.id, "JOINABLE_ROLES") try: role = await commands.RoleConverter().convert(ctx, roleraw) if role.id in role_list: role_list.remove(role.id) Configuration.setConfigVar(ctx.guild.id, "JOINABLE_ROLES", role_list) await ctx.send(f"{role.name} has been removed from the selfrole list.") else: await ctx.send("That role already isn't joinable!") except: if role in role_list: role_list.remove(role) Configuration.setConfigVar(ctx.guild.id, "JOINABLE_ROLES", role_list) await ctx.send("Role successfully removed from the selfrole list.") else: await ctx.send("That role already isn't joinable or if you are trying to remove a role from the selfrole list you have already deleted please use the ID.")
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["mysql"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files) gen_investors(context, conf)
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["hosts", "mysql"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files) process_assert(tinit_md(context, conf))
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["xmq"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files) pushpull.PPServer.start_server(context, conf)
def permission_official(member_id, permission_name): # ban permission on official server - sort of a hack to propagate perms # TODO: better permissions model try: official_guild = BOT.get_guild(Configuration.get_var("guild_id")) official_member = official_guild.get_member(member_id) return getattr(official_member.guild_permissions, permission_name) except Exception: return False
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["hosts"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files) rsync.rsync_groups(context, conf)
def isServerMod(ctx: commands.Context): if ctx.guild is None: return False modrole = Configuration.getConfigVar(ctx.guild.id, "MOD_ROLE_ID") if modrole != 0: for role in ctx.author.roles: if str(role.id) == str(modrole): return True return isServerAdmin(ctx)
def isServerAdmin(ctx: commands.Context): if ctx.guild is None: return False adminrole = Configuration.getConfigVar(ctx.guild.id, "ADMIN_ROLE_ID") if adminrole != 0: for role in ctx.author.roles: if str(role.id) == str(adminrole): return True return ctx.author == ctx.guild.owner
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["xmq", "redis", "mysql", "exchange"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files) start_md_service(context=context, conf=conf)
async def on_member_unban(self, guild, user): while not self.bot.startup_done: await asyncio.sleep(1) channelid = Configuration.getConfigVar(guild.id, "MOD_LOGS") if channelid is not 0: logChannel: discord.TextChannel = self.bot.get_channel(channelid) if logChannel is not None: await logChannel.send( f":rotating_light: {user.display_name}#{user.discriminator} (`{user.id}`) has been unbanned from the server." )
def set_verification_mode(self, guild): # TODO: enforce channel permissions for entry_channel? # verification flow is on if entry channel is set ec = self.bot.get_guild_entry_channel(guild.id) self.discord_verification_flow[guild.id] = bool(ec) # Do not mute new members if verification flow is on. # Otherwise, mute new members UNLESS it's manually overridden self.mute_new_members[guild.id] = False if self.discord_verification_flow[guild.id] else \ Configuration.get_persistent_var(f"{guild.id}_mute_new_members", True)
async def on_ready(self): Logging.info(f"Skybot... {'RECONNECT!' if self.loaded else 'STARTUP!'}") if self.loaded: Logging.info("Skybot reconnect") return Logging.BOT_LOG_CHANNEL = self.get_channel(Configuration.get_var("log_channel")) Emoji.initialize(self) for cog in Configuration.get_var("cogs"): try: self.load_extension("cogs." + cog) except Exception as e: await Utils.handle_exception(f"Failed to load cog {cog}", self, e) Logging.info("Cogs loaded") self.db_keepalive = self.loop.create_task(self.keepDBalive()) self.loaded = True await Logging.bot_log("Skybot soaring through the skies!")
async def on_member_remove(self, member: discord.Member): while not self.bot.startup_done: await asyncio.sleep(1) channelid = Configuration.getConfigVar(member.guild.id, "JOIN_LOGS") if channelid is not 0: logChannel: discord.TextChannel = self.bot.get_channel(channelid) if logChannel is not None: await logChannel.send( f":outbox_tray: {member.display_name}#{member.discriminator} (`{member.id}`) has left the server." )
async def send_bug_info(self, key): channel = self.bot.get_channel(Configuration.get_var("channels")[key]) bug_info_id = Configuration.get_persistent_var(f"{key}_message") if bug_info_id is not None: try: message = await channel.fetch_message(bug_info_id) except NotFound: pass else: await message.delete() if message.id in self.bug_messages: self.bug_messages.remove(message.id) bugemoji = Emoji.get_emoji('BUG') message = await channel.send( Lang.get_string("bugs/bug_info", bug_emoji=bugemoji)) await message.add_reaction(bugemoji) self.bug_messages.add(message.id) Configuration.set_persistent_var(f"{key}_message", message.id)
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["mysql"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files, add_ons=add_ons) process_assert(settle_activity(context, conf))
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["hosts"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files, add_ons=add_ons) service_shell.execute_command(context, conf)
def main(): base_dir, config_names, config_files, add_ons = parse_conf_args( __file__, config_names=["exchange", "xmq"]) context, conf = Configuration.load(base_dir=base_dir, config_names=config_names, config_files=config_files, add_ons=add_ons) start_get_md_quotes(context, conf)
async def startup_cleanup(self): restart_mid = Configuration.get_persistent_var("bot_restart_message_id") restart_cid = Configuration.get_persistent_var("bot_restart_channel_id") author_id = Configuration.get_persistent_var("bot_restart_author_id") Configuration.del_persistent_var("bot_restart_message_id", True) Configuration.del_persistent_var("bot_restart_channel_id", True) Configuration.del_persistent_var("bot_restart_author_id", True) # TODO: write pop_persistent_var if restart_cid and restart_mid: try: channel = self.bot.get_channel(restart_cid) message = await channel.fetch_message(restart_mid) author = self.bot.get_user(author_id) await message.edit(content=f"Restart complete {author.mention}") except Exception: pass
async def on_ready(self): if self.loaded: Logging.info(f"{self.my_name} reconnect") return Logging.BOT_LOG_CHANNEL = self.get_channel( Configuration.get_var("log_channel")) Emoji.initialize(self) for cog in Configuration.get_var("cogs"): try: self.load_extension("cogs." + cog) except Exception as e: await Utils.handle_exception(f"Failed to load cog {cog}", self, e) Logging.info("Cogs loaded") self.db_keepalive = self.loop.create_task(self.keepDBalive()) self.loaded = True await Logging.bot_log(f"{self.my_name} has started. Time to bot!")
async def on_member_remove(self, member): # clear rules reactions roles = Configuration.get_var("roles") guild = self.bot.get_guild(member.guild.id) self.remove_member_from_cooldown(guild.id, member.id) rules_channel = self.bot.get_config_channel(guild.id, Utils.rules_channel) rules_message_id = Configuration.get_var('rules_react_message_id') try: rules = await rules_channel.fetch_message(rules_message_id) except Exception as e: return for reaction, role_id in roles.items(): try: await rules.remove_reaction(reaction, member) except Exception as e: pass
async def announce(self, ctx: commands.Context, role_name, *, message): Admins = discord.utils.get(ctx.guild.roles, id=485125261470203905) role = Configuration.get_role(ctx, role_name) channel = Configuration.get_channel(ctx, role_name) if 485125261470203905 not in [role.id for role in ctx.author.roles]: return if role is None: return await ctx.send("This role might have been deleted, oops!") if message != None: await role.edit(mentionable=True) try: await channel.send(f"{role.mention}\n{message}") except discord.Forbidden: await ctx.send("I was not able to send a message. Can you check to make sure I have permission?") await role.edit(mentionable=False) else: await ctx.send("I am unsure of what you are attempting to do.")
def is_member_verified(self, member): try: guild = Utils.get_home_guild() if member.guild.id != guild.id: return True # non-members are "verified" so we don't try to interact with them member_role = guild.get_role(Configuration.get_var("member_role")) if member_role not in member.roles: return False return True except Exception as ex: return True # exceptions are "verified" so we don't try to interact with them *again*
async def minorLogChannel(self, ctx: commands.Context, channel: discord.TextChannel): """Sets the logging channel for minor logs (edit/delete)""" if channel is None: raise BadArgument("Missing channel") permissions = channel.permissions_for( ctx.guild.get_member(self.bot.user.id)) if permissions.read_messages and permissions.send_messages and permissions.embed_links: old = Configuration.getConfigVar(ctx.guild.id, "MINOR_LOGS") Configuration.setConfigVar(ctx.guild.id, "MINOR_LOGS", channel.id) await ctx.send(f"{channel.mention} will now be used for minor logs" ) if old == 0: await ctx.send(f"Caching recent messages for logging...") await self.buildCache(ctx.guild) await ctx.send("Caching complete") else: await ctx.send( f"I cannot use {channel.mention} for logging, I do not have the required permissions in there (read_messages, send_messages and embed_links)." )
async def send_bug_info(self, *args): for channel_id in args: channel = self.bot.get_channel(channel_id) if channel is None: await Logging.bot_log(f"can't send bug info to nonexistent channel {channel_id}") continue bug_info_id = Configuration.get_persistent_var(f"{channel.guild.id}_{channel_id}_bug_message") ctx = None tries = 0 while not ctx and tries < 5: tries += 1 # this API call fails on startup because connection is not made yet. # TODO: properly wait for connection to be initialized try: last_message = await channel.send('preparing bug reporting...') ctx = await self.bot.get_context(last_message) if bug_info_id is not None: try: message = await channel.fetch_message(bug_info_id) except (NotFound, HTTPException): pass else: await message.delete() if message.id in self.bug_messages: self.bug_messages.remove(message.id) bugemoji = Emoji.get_emoji('BUG') message = await channel.send(Lang.get_locale_string("bugs/bug_info", ctx, bug_emoji=bugemoji)) self.bug_messages.add(message.id) await message.add_reaction(bugemoji) Configuration.set_persistent_var(f"{channel.guild.id}_{channel_id}_bug_message", message.id) Logging.info(f"Bug report message sent in channel #{channel.name} ({channel.id})") await last_message.delete() except Exception as e: await self.bot.guild_log(channel.guild.id, f'Having trouble sending bug message in {channel.mention}') await Utils.handle_exception( f"Bug report message failed to send in channel #{channel.name} ({channel.id})", self.bot, e) await asyncio.sleep(0.5)
def init_guild(self, guild_id): watch = ReactWatch.get_or_create(serverid=guild_id)[0] self.mutes[guild_id] = Configuration.get_persistent_var(f"react_mutes_{guild_id}", dict()) self.min_react_lifespan[guild_id] = Configuration.get_persistent_var(f"min_react_lifespan_{guild_id}", 0.5) self.mute_duration[guild_id] = watch.muteduration # track react add/remove per guild self.recent_reactions[guild_id] = dict() self.react_removers[guild_id] = dict() self.react_adds[guild_id] = dict() # list of emoji to watch self.emoji[guild_id] = dict() for e in watch.emoji: self.emoji[guild_id][e.emoji] = e # enable listening if set in db if watch.watchremoves: self.activate_react_watch(guild_id) self.guilds[guild_id] = Guild.get_or_create(serverid=guild_id)[0]
def run_db_migrations(): dbv = int(Configuration.get_persistent_var('db_version', 0)) Logging.info(f"db version is {dbv}") dbv_list = [f for f in glob.glob("db_migrations/db_migrate_*.py")] dbv_pattern = re.compile(r'db_migrations/db_migrate_(\d+)\.py', re.IGNORECASE) migration_count = 0 for filename in sorted(dbv_list): # get the int version number from filename version = int(re.match(dbv_pattern, filename)[1]) if version > dbv: try: Logging.info(f"--- running db migration version number {version}") spec = importlib.util.spec_from_file_location(f"migrator_{version}", filename) dbm = importlib.util.module_from_spec(spec) spec.loader.exec_module(dbm) Configuration.set_persistent_var('db_version', version) migration_count = migration_count + 1 except Exception as e: # throw a fit if it doesn't work raise e Logging.info(f"--- {migration_count if migration_count else 'no'} db migration{'' if migration_count == 1 else 's'} run")
#!/usr/bin/env python import web import time from utils import logs from utils import Configuration render = web.template.render('templates/') urls = ('/', 'index', '/sendlogs(.*)', 'sendlogs') conf = Configuration() lr = logs.LogReader() LOG_LEVEL = conf.log_level() LOG_MAIL = conf.log_mail() class index(object): """ Main web page. """ def GET(self): timestamp = time.ctime(time.time()) logs_names, logs_cont = lr.get_logs() return render.index(LOG_LEVEL, logs_names, logs_cont, timestamp) class sendlogs(object): def GET(self, *args):