Beispiel #1
0
    async def sub(self, ctx, channel: discord.TextChannel = None, *args):

        determiner = 'That'
        if channel is None:
            channel = ctx.message.channel
            determiner = 'This'

        exists = query.exists('subscriptions_contests', 'channel_id',
                              channel.id)

        old_sub_int = None
        old_sub_bin = None

        ojs = []
        for arg in args:
            try:
                oj = self.onlineJudges.get_oj(arg)
                if oj not in self.onlineJudges.contest_judges:
                    raise NoSuchOJException
                ojs.append(oj)
            except NoSuchOJException:
                await ctx.send(
                    ctx.message.author.display_name +
                    ', Invalid query. The online judges must be one of the following: %s.'
                    % self.onlineJudges.contest_judges_str())
                return

        sub_bin = '0' * len(self.onlineJudges.contest_judges)
        if exists:
            old_sub_int = query.get_subbed_ojs(channel.id)
            old_sub_bin = '{0:b}'.format(old_sub_int).zfill(
                len(self.onlineJudges.contest_judges))
            sub_bin = old_sub_bin
        selected = 'the selected '
        if len(ojs) == 0:
            sub_bin = '1' * len(self.onlineJudges.contest_judges)
            selected = 'all '
        sub_bin_mutable = list(sub_bin)
        for oj in ojs:
            sub_bin_mutable[self.onlineJudges.contest_judges.index(oj)] = '1'
        sub_bin = ''.join(sub_bin_mutable)
        sub_int = int(sub_bin, 2)

        if exists and sub_int == old_sub_int:
            await ctx.send(
                ctx.message.author.display_name +
                ', %s channel is already subscribed to %scontest notifications.'
                % (determiner, selected))
            return
        if not exists:
            query.sub_channel(channel.id)
        query.update_subbed_ojs(channel.id, sub_int)
        await ctx.send(ctx.message.author.display_name + ', ' +
                       channel.mention +
                       ' subscribed to %scontest notifications.' % selected)
Beispiel #2
0
 async def subs(self, ctx):
     clist = ctx.message.author.display_name + ', Contest notification channels in this server:\n'
     for text_channel in ctx.message.guild.text_channels:
         if query.exists('subscriptions_contests', 'channel_id',
                         text_channel.id):
             clist += text_channel.mention + '\n'
     if clist == ctx.message.author.display_name + ', Contest notification channels in this server:\n':
         await ctx.send(
             ctx.message.author.display_name +
             ', There are no channels subscribed to contest notifications in this server :slight_frown:'
         )
     else:
         await ctx.send(clist)
Beispiel #3
0
    async def serverinfo(self, ctx):
        if ctx.message.guild is None:
            await ctx.send(
                ctx.message.author.display_name +
                ', You can only request for server info within a server!')
            return

        query.insert_ignore_server(ctx.message.guild.id)
        server_data = query.get_server(ctx.message.guild.id)

        embed = discord.Embed(title=ctx.message.guild.name)
        embed.timestamp = datetime.utcnow()
        embed.set_thumbnail(url=ctx.message.guild.icon_url)
        embed.colour = discord.Colour(int('ffd300', 16))

        embed.add_field(
            name='Nickname sync',
            value=str(server_data[ctx.message.guild.id]['nickname_sync'] == 1)
            +
            ' (If true, nicknames will be set automatically based on the sync source)',
            inline=False)
        embed.add_field(
            name='Role sync',
            value=str(server_data[ctx.message.guild.id]['role_sync'] == 1) +
            ' (If true, roles will be set automatically based on the sync source)',
            inline=False)
        if server_data[ctx.message.guild.id]['nickname_sync'] or server_data[
                ctx.message.guild.id]['role_sync']:
            embed.add_field(
                name='Sync source',
                value=server_data[ctx.message.guild.id]['sync_source'],
                inline=False)
        embed.add_field(
            name='Join message',
            value=str(server_data[ctx.message.guild.id]['join_message'] == 1) +
            ' (If true, bot will send a default join message whenever a new member joins your server)',
            inline=False)
        prefix = await self.bot.command_prefix(self.bot, ctx.message)
        embed.add_field(name='Server prefix', value=prefix, inline=False)
        clist = ''
        for text_channel in ctx.message.guild.text_channels:
            if query.exists('subscriptions_contests', 'channel_id',
                            text_channel.id):
                clist += text_channel.mention + '\n'
        embed.add_field(name='Contest notification channel(s)',
                        value='None' if clist == '' else clist,
                        inline=False)
        await ctx.send(ctx.message.author.display_name +
                       ', Here is your requested info!',
                       embed=embed)
Beispiel #4
0
 async def sub(self, ctx, channel: discord.TextChannel = None):
     determiner = 'That'
     if channel is None:
         channel = ctx.message.channel
         determiner = 'This'
     if query.exists('subscriptions_contests', 'channel_id', channel.id):
         await ctx.send(
             ctx.message.author.display_name +
             ', %s channel is already subscribed to contest notifications.'
             % determiner)
         return
     query.sub_channel(channel.id)
     await ctx.send(ctx.message.author.display_name + ', ' +
                    channel.mention +
                    ' subscribed to contest notifications.')
Beispiel #5
0
 async def subs(self, ctx):
     clist = ctx.message.author.display_name + ', Contest notification channels in this server:\n'
     for text_channel in ctx.message.guild.text_channels:
         if query.exists('subscriptions_contests', 'channel_id',
                         text_channel.id):
             sub_bin = '{0:b}'.format(query.get_subbed_ojs(
                 text_channel.id)).zfill(
                     len(self.onlineJudges.contest_judges))
             ojs = []
             for i, b in enumerate(sub_bin):
                 if b == '1':
                     ojs.append(self.onlineJudges.contest_judges[i])
             clist += text_channel.mention + ' `' + ', '.join(ojs) + '`\n'
     if clist == ctx.message.author.display_name + ', Contest notification channels in this server:\n':
         await ctx.send(
             ctx.message.author.display_name +
             ', There are no channels subscribed to contest notifications in this server :slight_frown:'
         )
     else:
         await ctx.send(clist)