def update_should_verify(g_id): g = Guild.objects(guild_id=g_id).first() if not g: raise exceptions.UpdateError("Cannot update should_verify") g.should_verify = not g.should_verify g.save() return g.should_verify
def update_should_save_messages(g_id) -> bool: g = Guild.objects().filter(guild_id=g_id).first() if not g: raise exceptions.UpdateError("Couldn't update 'should_save_message'") g.should_save_messages = not g.should_save_messages g.save() return g.should_save_messages
def update_should_show_edited(g_id) -> bool: g = Guild.objects(guild_id=g_id).first() if not g: raise exceptions.UpdateError("Cannot update should_show_edited") g.should_show_edited = not g.should_show_edited g.save() return g.should_show_edited
def get_verified_role_in_guild(guild: discord.Guild) -> discord.Role: g = Guild.objects(guild_id=guild.id).first() r = Role.objects(id__in=g.roles) \ .filter(category="verify") \ .first() if not r: return None return guild.get_role(r.role_id)
def get_role_from_payload(payload: discord.RawReactionActionEvent, guild: discord.Guild) -> discord.Role: g = Guild.objects(guild_id=payload.guild_id).first() r = Role.objects(id__in=g.roles) \ .filter(message_id=payload.message_id) \ .filter(reaction=payload.emoji.name).first() if not r: return None return guild.get_role(r.role_id)
def should_show_deleted_in_guild(g_id) -> bool: g = Guild.objects().filter(guild_id=g_id).first() if not g: raise exceptions.UpdateError("An error has occured") if not g.log_channel: raise exceptions.UpdateError( "There is no log channel set yet.\n Use `!.slc` to assign a channel to logging" ) return g.should_show_deleted
def update_guild_welcome_message(guild: discord.Guild, message) -> str: g = Guild.objects().filter(guild_id=guild.id).first() if not g: create_default_guild(guild) r = update_guild_welcome_message(guild, messages) return r g.welcome_message = message g.save() return g.welcome_message
def get_log_channel_in_guild(guild: discord.Guild) -> discord.TextChannel: g = Guild.objects().filter(guild_id=guild.id).first() if not g: raise exceptions.UpdateError("An error has occured") if not g.log_channel: raise exceptions.UpdateError("There is no log channel set") c = guild.get_channel(g.log_channel) if not c: raise exceptions.UpdateError("Couldn't find the log channel") return c
def update_should_show_deleted(g_id) -> bool: g = Guild.objects().filter(guild_id=g_id).first() if not g: raise exceptions.UpdateError("Couldn't update 'should_show_deleted'") if not g.log_channel: raise exceptions.UpdateError( "There is no log channel set yet.\n Use `!.slc` to assign a channel to logging" ) g.should_show_deleted = not g.should_show_deleted g.save() return g.should_show_deleted
def create_default_guild(guild: discord.Guild): g = get_guild(guild.id) if not g: g = Guild() g.name = guild.name g.guild_id = guild.id g.welcome_message = messages.DEFAULT_WELCOME_MESSAGE.format(guild.name) g.save()
def add_guilds(bot, update): if ('⛺' in update.message.text or '😴' in update.message.text ) and update.message.forward_from_chat.username == 'ChatWarsDigest': battletime = update.message.forward_date session = db_session.create_session() guilds = filter(lambda x: '[' in x, update.message.text.split()) existing_guilds = [_[0] for _ in session.query(Guild.tag).all()] tags = set() for guild in guilds: tag = guild[0] + guild.split('[')[-1].split(']')[0] if tag not in existing_guilds and tag not in tags: session.add(Guild(tag=tag)) tags.add(tag) session.commit() for tag in tags: session.add( Battle(guildid=session.query( Guild.id).filter(Guild.tag == tag).one()[0], battletime=battletime.replace(minute=0, second=0))) session.commit() update.message.reply_text('Результаты сражений приняты.')
def increment_retarded_user(g_id): Guild.objects(guild_id=g_id).update_one(inc__retarded_user=1)
def channel_is_verification(ctx: discord.ext.commands.Context) -> bool: return Guild.objects( guild_id=ctx.guild.id).first().verification_channel == ctx.channel.id
def increment_message_edited(g_id: discord.Guild.id): Guild.objects(guild_id=g_id).update_one(inc__message_edited=1)
def should_save_messages_in_guild(g_id) -> bool: g = Guild.objects().filter(guild_id=g_id).first() if not g: return False return g.should_save_messages
def update_log_channel_in_guild(g_id, c_id): g = Guild.objects().filter(guild_id=g_id).first() if not g: raise exceptions.UpdateError("Couldn't set the log channel") g.log_channel = c_id g.save()
def get_guild(g_id): return Guild.objects().filter(guild_id=g_id).first()
def should_welcome_in_guild(g_id) -> bool: g = Guild.objects().filter(guild_id=g_id).first() if not g: return False return g.should_welcome_members
def get_password_in_guild(g_id) -> str: return Guild.objects(guild_id=g_id).first().password
def increment_underaged_user(g_id): Guild.objects(guild_id=g_id).update_one(inc__underaged_user=1)
def increment_verified_user(g_id): Guild.objects(guild_id=g_id).update_one(inc__verified_user=1)