Exemplo n.º 1
0
def main():
    Connector.init()
    Analytics.init()

    client.load_extension(f'TopGGModule')
    client.load_extension(f'DiscordBotListModule')
    client.load_extension(f'ReminderModule')
    client.load_extension(f'ReminderListing')
    client.run(token)
Exemplo n.º 2
0
    async def update_stats(self):
        """This function runs every 30 minutes to automatically update your server count."""

        server_count = len(self.client.guilds)
        Analytics.current_guilds(server_count)

        payload = {
            'server_count': server_count
        }
        if self.client.shard_count:
            payload["shard_count"] = self.client.shard_count
        if self.client.shard_id:
            payload["shard_id"] = self.client.shard_id

        await self.post_count( f'/bots/{self.client.user.id}/stats', payload=payload)
Exemplo n.º 3
0
    async def on_component(self, ctx: ComponentContext):

        if ctx.component.get('label', '') != 'Delete' or \
            ctx.component.get('emoji', {}).get('name', '') != '🗑️':
            return  # some other routine must take care of this

        try:
            rem_id = ObjectId(ctx.custom_id)
        except:
            return

        if Connector.delete_reminder(rem_id):
            await ctx.send('Deleted the reminder', hidden=True)
            Analytics.delete_reminder()
        else:
            await ctx.send(
                'Could not find a matching reminder for this component.\nThe reminder is already elapsed or was already deleted',
                hidden=True)
Exemplo n.º 4
0
    async def check_reminder_cnt(self):
        now = datetime.utcnow()

        rems = Connector.get_reminder_cnt()
        Analytics.active_reminders(rems)
Exemplo n.º 5
0
    async def process_reminder(self, ctx, author, target, period, message):

        if ctx.guild:
            tz_str = Connector.get_timezone(author.guild.id)

            # try and get the last message, for providing a jump link
            try:
                last_msg = await ctx.channel.history(limit=1).flatten()
            except:
                last_msg = None

            last_msg = last_msg[0] if last_msg else None
        else:
            tz_str = 'UTC'
            last_msg = None

        err = False

        utcnow = datetime.utcnow()
        remind_at, info = lib.input_parser.parse(period, utcnow, tz_str)

        if (remind_at - utcnow) <= timedelta(hours=0):
            out_str = ''
            if info:
                print('received invalid format string')
                out_str += f'```Parsing hints:\n{info}```\n'
                out_str += ReminderModule.REMIND_FORMAT_HELP
                Analytics.invalid_f_string()
            else:
                print('received negative reminder interval')
                out_str += f'```the interval must be greater than 0```'
                Analytics.invalid_f_string()

            embed = discord.Embed(title='Failed to create the reminder',
                                  description=out_str)
            await ctx.send(embed=embed, hidden=True)
            return

        await ctx.defer(
        )  # allow more headroom for response latency, before command fails
        rem = Reminder()

        if ctx.guild:
            rem.g_id = ctx.guild.id
            rem.ch_id = ctx.channel_id
        else:
            # command was called in DM
            rem.g_id = None
            rem.ch_id = None

        rem.msg = message
        rem.at = remind_at
        rem.author = author.id
        rem.target = target.id
        rem.created_at = utcnow
        rem.last_msg_id = last_msg.id if last_msg else None

        # the id is required in case the users wishes to abort
        rem_id = Connector.add_reminder(rem)

        if rem.author == rem.target:
            Analytics.add_self_reminder(rem)
        else:
            Analytics.add_foreign_reminder(rem)

        # convert reminder period to readable delta
        # convert utc date into readable local time (locality based on server settings)
        delta_str = ReminderModule.delta_to_str(remind_at - utcnow)
        if tz_str == 'UTC':
            # this workaround is required, as system uses german term for UTC
            at_str = remind_at.strftime('%Y/%m/%d %H:%M UTC')
        else:
            at_str = remind_at.replace(tzinfo=tz.UTC).astimezone(
                tz.gettz(tz_str)).strftime('%Y/%m/%d %H:%M %Z')

        if target == author:
            out_str = f'Reminding you in `{delta_str}` at `{at_str}`.'
        else:
            out_str = f'Reminding {target.name} in `{delta_str}` at `{at_str}`.'

        if (remind_at - utcnow) < timedelta(minutes=5):
            out_str += '\nBe aware that the reminder can be as much as 1 minute delayed'

        if info:
            out_str += f'\n```Parsing hints:\n{info}```'

        # create the button to delete this reminder
        buttons = [
            manage_components.create_button(style=ButtonStyle.danger,
                                            label='Delete',
                                            emoji='🗑️',
                                            custom_id=str(rem_id))
        ]
        action_row = manage_components.create_actionrow(*buttons)

        # delta_to_str cannot take relative delta
        msg = await ctx.send(out_str,
                             delete_after=300,
                             components=[action_row])
Exemplo n.º 6
0
async def on_guild_join(guild):
    Analytics.add_guild(guild.id)
    print(f'added to guild (total count: {len(client.guilds)})')
Exemplo n.º 7
0
async def on_guild_remove(guild):
    Connector.delete_guild(guild.id)
    Analytics.delete_guild(guild.id)
    print(f'removed from guild (total count: {len(client.guilds)})')