Esempio n. 1
0
async def on_ready():

    await bot.change_presence(activity=discord.Activity(
        name='everything', type=discord.ActivityType(3)))
    if not started():
        await asyncio.create_task(bg_tasks(bot))
    print('ready')
Esempio n. 2
0
async def _on_away(self, client, tags, cmd, args):
    game = ' '.join(args)
    if game.startswith(':'):
        game = game[1:]
    ptype = (tags and tags.get('+discordapp.com/type') or '').lower()
    url   = None
    if ptype == 'watching':
        ptype = 3
    elif ptype == 'listening to':
        ptype = 2
    elif ptype == 'streaming':
        ptype = 1
        url  = 'https://www.twitch.tv/directory'
    else:
        ptype = 0

    game = discord.Activity(name = game, type = discord.ActivityType(ptype),
        url = url)
    self.debug('Changing online presence:', game)

    if tags.get('+discordapp.com/status'):
        try:
            status = discord.Status(tags['+discordapp.com/status'])
        except:
            print('WARNING: Invalid status sent to AWAY!')
            return
    else:
        status = discord.Status('online')

    await client.change_presence(activity=game, status=status)
Esempio n. 3
0
async def ready_tasks():
    bot.db = await aiosqlite.connect('DimBot.db')
    # bot.add_cog(raceline.Ricciardo(bot))  # Enable when finishes async db
    bot.add_cog(Verstapen(bot))
    bot.add_cog(Bottas(bot))
    bot.add_cog(bitbay.BitBay(bot))
    bot.add_cog(dimond.Dimond(bot))
    bot.add_cog(Ikaros(bot))
    bot.add_cog(Aegis(bot))
    bot.add_cog(XP(bot))
    await bot.wait_until_ready()
    bot.add_cog(tribe.Hamilton(bot))
    bot.eggy = await bot.fetch_user(226664644041768960)  # Special Discord user
    await bot.is_owner(bot.eggy)  # Trick to set bot.owner_id
    logger.info('Ready')
    # Then updates the nickname for each server that DimBot is listening to
    for guild in bot.guilds:
        if guild.me.nick != nickname:
            bot.loop.create_task(guild.me.edit(nick=nickname))
    if reborn_channel:  # Post-process Pandora if needed
        await bot.get_channel(reborn_channel).send(
            "Arc-Cor𐑞: Pandora complete.")
    while True:
        activity = await bot.sql.get_activity(bot.db)
        await bot.change_presence(activity=discord.Activity(
            name=activity[0], type=discord.ActivityType(activity[1])))
        await asyncio.sleep(300)
        await bot.db.commit()
        logger.debug('DB auto saved')
Esempio n. 4
0
async def ready_tasks():
    bot.add_cog(Ricciardo(bot))
    bot.add_cog(Verstapen(bot))
    bot.add_cog(Bottas(bot))
    bot.add_cog(diminator.Diminator(bot))
    bot.add_cog(dimond.Dimond(bot))
    bot.add_cog(Ikaros(bot))
    bot.add_cog(Aegis(bot))
    bot.add_cog(XP(bot))
    bot.add_cog(Games(bot))
    await bot.wait_until_ready()
    bot.add_cog(tribe.Hamilton(bot))
    bot.after_invoke(ainvk)
    psutil.cpu_percent(percpu=True)
    await bot.is_owner(bot.user)  # Trick to set bot.owner_id
    logger.info('Ready')
    if reborn_channel:  # Post-process Pandora if needed
        await bot.get_channel(reborn_channel).send(
            "Arc-Cor𐑞: Pandora complete.")
    # Then updates the nickname for each server that DimBot is listening to
    for guild in bot.guilds:
        if guild.me.nick != nickname and guild.me.guild_permissions.change_nickname:
            bot.loop.create_task(guild.me.edit(nick=nickname))
    while True:
        activity = await bot.sql.get_activity(bot.db)
        await bot.change_presence(activity=discord.Activity(
            name=activity[0], type=discord.ActivityType(activity[1])),
                                  status=bot.status)
        await asyncio.sleep(300)
        await bot.db.commit()
        logger.debug('DB auto saved')
Esempio n. 5
0
async def on_ready():
    bot.add_check(check_command)
    await bot.change_presence(activity=discord.Activity(
        name='everything', type=discord.ActivityType(3)))
    # print(len(bot.commands))
    if not started():
        bot.loop.create_task(spam_chart_daemon(bot))
        bot.loop.create_task(bg_tasks(bot))
Esempio n. 6
0
 async def next_status(self):
     """switch to the next status message"""
     activity_type, status_func = next(self.statuses)
     await self.bot.change_presence(
         status=discord.Status.online,
         activity=discord.Activity(
             type=discord.ActivityType(self.activity_id[activity_type]),
             name=status_func(),
         ),
     )
Esempio n. 7
0
    def get(self, key: str, convert=True) -> typing.Any:
        value = self.__getitem__(key)

        if not convert:
            return value

        if key in self.colors:
            try:
                return int(value.lstrip("#"), base=16)
            except ValueError:
                logger.error("Invalid %s provided.", key)
            value = int(self.remove(key).lstrip("#"), base=16)

        elif key in self.time_deltas:
            if value is None:
                return
            try:
                value = isodate.parse_duration(value)
            except isodate.ISO8601Error:
                logger.warning(
                    "The {account} age limit needs to be a "
                    'ISO-8601 duration formatted duration, not "%s".',
                    value,
                )
                value = self.remove(key)

        elif key in self.booleans:
            try:
                value = strtobool(value)
            except ValueError:
                value = self.remove(key)

        elif key in self.special_types:
            if value is None:
                return

            if key == "status":
                try:
                    # noinspection PyArgumentList
                    value = discord.Status(value)
                except ValueError:
                    logger.warning("Invalid status %s.", value)
                    value = self.remove(key)

            elif key == "activity_type":
                try:
                    # noinspection PyArgumentList
                    value = discord.ActivityType(value)
                except ValueError:
                    logger.warning("Invalid activity %s.", value)
                    value = self.remove(key)

        return value
Esempio n. 8
0
    async def next_status(self):
        """switch to the next status message."""
        new_status_id = self.current_status
        while new_status_id == self.current_status:
            new_status_id = random.randrange(0, len(self.statuses))

        status = self.statuses[new_status_id]
        self.current_status = new_status_id

        await self.bot.change_presence(activity=discord.Activity(
            type=discord.ActivityType(self.activities[status[0]]),
            name=status[1]()))
Esempio n. 9
0
async def getRandStatus() -> discord.Activity:

    # activity types:
    # -1 : unknown
    # 0  : playing
    # 1  : streaming
    # 2  : listening
    # 3  : watching

    # set placeholder vars
    listening = discord.ActivityType(2)
    watching = discord.ActivityType(3)

    # the list of all possible statuses
    statusList = [
        # playing ...
        discord.Game(name='with fire'),  # playing with fire
        discord.Game(name='with blood'),  # playing with blood
        discord.Game(name='with Izzy'),  # playing with Izzy
        discord.Game(name='with my minions'),

        # streaming ...
        discord.Streaming(name="the Summoning",
                          url="https://www.instagram.com/theizzycomics/"
                          ),  # links to izzy's insta :p
        discord.Streaming(name="Izzy Merch",
                          url="http://theizzypeasy.ecwid.com/"),

        # listening to ...
        discord.Activity(name="screams of the damned",
                         type=listening),  # listening to 

        # watching ...
        discord.Activity(name="the guilty burn",
                         type=watching)  # watching the guilty burn
    ]

    # select one and return
    index = randint(0, len(statusList) - 1)
    return statusList[index]
Esempio n. 10
0
    def get(self, key: str, convert=True) -> typing.Any:
        value = self.__getitem__(key)

        if not convert:
            return value

        if key in self.colors:
            try:
                return int(value.lstrip("#"), base=16)
            except ValueError:
                logger.error("Inválido %s.", key)
            value = int(self.remove(key).lstrip("#"), base=16)

        elif key in self.time_deltas:
            if not isinstance(value, isodate.Duration):
                try:
                    value = isodate.parse_duration(value)
                except isodate.ISO8601Error:
                    logger.warning(
                        "El límite de edad de la cuenta ${account} debe ser un"
                        'ISO-8601 duración formateada, no "%s".',
                        value,
                    )
                    value = self.remove(key)

        elif key in self.booleans:
            try:
                value = strtobool(value)
            except ValueError:
                value = self.remove(key)

        elif key in self.special_types:
            if value is None:
                return None

            if key == "status":
                try:
                    # noinspection PyArgumentList
                    value = discord.Status(value)
                except ValueError:
                    logger.warning("Estado inválido %s.", value)
                    value = self.remove(key)

            elif key == "activity_type":
                try:
                    # noinspection PyArgumentList
                    value = discord.ActivityType(value)
                except ValueError:
                    logger.warning("Actividad inválida %s.", value)
                    value = self.remove(key)

        return value
Esempio n. 11
0
    def get(self, key: str, convert=True) -> typing.Any:
        value = self.__getitem__(key)

        if not convert:
            return value

        if key in self.colors:
            try:
                return int(value.lstrip("#"), base=16)
            except ValueError:
                logger.error("Invalid %s provided.", key)
            value = int(self.remove(key).lstrip("#"), base=16)

        elif key in self.time_deltas:
            if not isinstance(value, isodate.Duration):
                try:
                    value = isodate.parse_duration(value)
                except isodate.ISO8601Error:
                    logger.warning(
                        "L'età di {account} deve essere una durata "
                        'formattata in ISO-8601, non "%s".',
                        value,
                    )
                    value = self.remove(key)

        elif key in self.booleans:
            try:
                value = strtobool(value)
            except ValueError:
                value = self.remove(key)

        elif key in self.special_types:
            if value is None:
                return None

            if key == "status":
                try:
                    # noinspection PyArgumentList
                    value = discord.Status(value)
                except ValueError:
                    logger.warning("Stato non valido: %s.", value)
                    value = self.remove(key)

            elif key == "activity_type":
                try:
                    # noinspection PyArgumentList
                    value = discord.ActivityType(value)
                except ValueError:
                    logger.warning("Attività non valida: %s.", value)
                    value = self.remove(key)

        return value
Esempio n. 12
0
async def on_ready():
    global do_setup
    if do_setup:

        await write('bot_prefix', '?')

        await client.change_presence(activity=discord.Activity(
            name='Everything', type=discord.ActivityType(3)))
        print("I'm in")
        print(client.user)
        print('settings up background tasks')
        loop = client.loop
        tasks = loop.create_task(bgTasks())

        await tasks
    do_setup = False
Esempio n. 13
0
    def format_status(self,
                      status: Union[str, dict],
                      shard: int = 0,
                      **kwargs) -> discord.Activity:
        game_type = 0
        url = None
        if isinstance(status, dict):
            game_type: int = status.get("type", 0)
            url: Optional[str] = status.get("url")
            status: str = status.get("game")

        formatted = Placeholders.parse(status, self.bot, shard, **kwargs)
        # noinspection PyArgumentList
        return discord.Activity(name=formatted,
                                url=url,
                                type=discord.ActivityType(game_type))
Esempio n. 14
0
 async def update_status(self, statuses: List[str]):
     if not statuses:
         return
     status = choice(statuses)
     for shard in self.bot.shards.keys():
         try:
             game, game_type = self.format_status(status, shard=shard)
         except KeyError as e:
             log.warning(
                 "Encountered invalid placeholder {!s} while attempting to parse status "
                 "#{}, skipping status update.".format(e, statuses.index(status) + 1)
             )
             return
         game = discord.Activity(name=game, type=discord.ActivityType(game_type))
         await self.bot.change_presence(
             activity=game, status=self.bot.guilds[0].me.status, shard_id=shard
         )
Esempio n. 15
0
    async def changeStatus(self):
        status = [
            "Check Slash Commands!", "{} guilds",
            "\U0001F355 \U00002795 \U0001F34D \U000027A1 \U0001F4A9"
        ]

        if self.statusnum % 2 == 0:
            await self.client.change_presence(status=discord.Status.online,
                                              activity=discord.Game(status[0]))
        elif self.statusnum % 3 == 0:
            theStatus = status[1].format(len(self.client.guilds))
            await self.client.change_presence(
                status=discord.Status.online,
                activity=discord.Activity(name=theStatus,
                                          type=discord.ActivityType(3)))
        elif self.statusnum % 101 == 0:
            await self.client.change_presence(status=discord.Status.online,
                                              activity=discord.Game(status[2]))
            self.statusnum = 0

        self.statusnum += 1
Esempio n. 16
0
    async def changeStatus(self):
        status = [
            "Use !help for directions!", "{} guilds for {} users",
            "\U0001F355 \U00002795 \U0001F34D \U000027A1 \U0001F4A9"
        ]

        if self.statusnum % 2 == 0:
            await self.client.change_presence(status=discord.Status.online,
                                              activity=discord.Game(status[0]))
        elif self.statusnum % 3 == 0:
            theStatus = status[1].format(
                len(self.client.guilds),
                len(set(self.client.get_all_members())))
            await self.client.change_presence(
                status=discord.Status.online,
                activity=discord.Activity(name=theStatus,
                                          type=discord.ActivityType(3)))
        elif self.statusnum % 101 == 0:
            await self.client.change_presence(status=discord.Status.online,
                                              activity=discord.Game(status[2]))
            self.statusnum = 0

        self.statusnum += 1