Esempio n. 1
0
def update_discord_server(plugin, discord_server, attr=None):
    if attr is None:
        attr = {}

    discord_server = plugin.db.DiscordServer[discord_server.id]

    if discord_server.state == 3:
        discord_server.state = 2

    before_data = discord_server.to_dict()

    discord_server.set(**attr)

    after_data = discord_server.to_dict()

    update_approval_queue(plugin)

    changelog_post_update(plugin, before_data, after_data)

    before_channel = get_channel_for_name_and_category(
        plugin, before_data['category_channel_name'],
        before_data['genre_category_name'])
    after_channel = get_channel_for_name_and_category(
        plugin, after_data['category_channel_name'],
        after_data['genre_category_name'])

    if before_channel:
        update_discord_index(plugin, only_in_channel_id=before_channel.id)
    if after_channel and after_channel.id != before_channel.id:
        update_discord_index(plugin, only_in_channel_id=after_channel.id)
Esempio n. 2
0
def add_discord_server(plugin,
                       invite_code,
                       server_id,
                       server_name,
                       server_description,
                       invitee_id,
                       category_channel_name,
                       genre_category_name,
                       author_id,
                       sudo=False):
    state = 1
    if sudo:
        state = 2

    entry = plugin.db.DiscordServer(
        state=state,
        invite_code=invite_code,
        server_id=server_id,
        name=server_name,
        description=server_description,
        invitee_id=invitee_id,
        submitted_at=datetime.datetime.now(),
        category_channel_name=category_channel_name,
        genre_category_name=genre_category_name,
        # index_message_id=789,
        last_checked=datetime.datetime.now())

    if sudo:
        changelog_post_approval(plugin, entry, author_id)
        index_channel = get_channel_for_name_and_category(
            plugin, entry.category_channel_name, entry.genre_category_name)
        if index_channel:
            update_discord_index(plugin, only_in_channel_id=index_channel.id)
    else:
        update_approval_queue(plugin)
Esempio n. 3
0
    def command_refresh_index(self, event):
        if event.msg.channel.guild_id != self.config.indexGuildID:
            return

        if not is_mod(self, event.msg.author.id):
            return
        self.client.api.channels_typing(event.msg.channel.id)
        update_discord_index(self)
        event.msg.reply('Refreshed index')
Esempio n. 4
0
def approve_queue_entry(plugin, entry, user_id):
    plugin.db.DiscordServer[entry.id].state = 2

    update_approval_queue(plugin)

    send_approval_message(plugin, entry)
    changelog_post_approval(plugin, entry, user_id)

    index_channel = get_channel_for_name_and_category(
        plugin, entry.category_channel_name, entry.genre_category_name)
    if index_channel:
        update_discord_index(plugin, only_in_channel_id=index_channel.id)
Esempio n. 5
0
def remove_discord_server(plugin, discord_server, author_user_id, reason=""):
    entry_data = discord_server.to_dict()

    discord_server.delete()

    update_approval_queue(plugin)

    changelog_post_removal(plugin, entry_data, author_user_id, reason)

    index_channel = get_channel_for_name_and_category(
        plugin, entry_data['category_channel_name'],
        entry_data['genre_category_name'])
    if index_channel:
        update_discord_index(plugin, only_in_channel_id=index_channel.id)
def start_servers_healthcheck(plugin):
    cutoff = datetime.datetime.now() - datetime.timedelta(hours=INVITE_CHECK_INTERVAL)

    for discord_server in orm.select(ds for ds in plugin.db.DiscordServer if ds.state == 2):
        if cutoff <= discord_server.last_checked:
            continue

        is_expired = False

        try:
            invite = plugin.client.api.invites_get(discord_server.invite_code)
        except APIException:
            is_expired = True

        if invite and not is_valid_invite(plugin, invite, discord_server.invitee_id,
                                          discord_server_entry=discord_server):
            is_expired = True

        discord_server.last_checked = datetime.datetime.now()
        if is_expired:
            discord_server.state = 3
            send_expiration_message(plugin, discord_server)
            changelog_post_expiration(plugin, discord_server)
            plugin.log.info(
                'invite expired '
                'server: #{entry[server_id]} discord.gg/{entry[invite_code]} '
                'name: {entry[name]} description: {entry[description]} '
                'category: {entry[category_channel_name]} genre: {entry[genre_category_name]} '
                'invitee: #{entry[invitee_id]} '
                'submitted at: {entry[submitted_at]} last checked: {entry[submitted_at]}'.format(
                    entry=discord_server.to_dict()))

            update_discord_index(plugin, only_in_channel_id=get_channel_for_name_and_category(plugin,
                                                                                              discord_server.category_channel_name,
                                                                                              discord_server.genre_category_name).id)

            orm.commit()
def start_discordindex_refresh(plugin):
    for channel_id in plugin.config.emojiChannelIDs:
        update_discord_index(plugin, only_in_channel_id=channel_id)
    for channel_id in plugin.config.rankedByMemberChannelIDs:
        update_discord_index(plugin, only_in_channel_id=channel_id)