Esempio n. 1
0
    async def reload(self, ctx: commands.context.Context):
        """
        Reload settings
        Reloading Filo will do the following:
            * Re-apply the verified role to member accounts
        """
        verified_role = await GuildSettings.fetch('verified', ctx)
        status = await ctx.send("Please wait..")

        if verified_role:
            async with ctx.typing():
                await status.edit(
                    content="Synchronizing verified member roles..")
                verified_members = list(Player.select().where(
                    Player.status == Player.STATUS_VERIFIED).execute())
                for member in verified_members:
                    self._log.info(
                        f"Synchronizing member {member.name} ({member.discord_id})"
                    )
                    member = ctx.guild.get_member(int(member.discord_id))
                    if member and verified_role not in member.roles:
                        print(
                            f"Adding verified member role to {member.display_name} ({member.id})"
                        )
                        await member.add_roles(verified_role)

        await status.delete()
        await ctx.send("Done!", delete_after=5.0)
Esempio n. 2
0
    async def youtube_to_mp3(self, ctx: commands.context.Context, *, video_url: str):
        with ctx.typing():
            video_info = youtube_dl.YoutubeDL().extract_info(
                url=video_url, download=False
            )

            filename = clean_filename(video_info['title'])

            SAVE_PATH = '/'.join(os.getcwd().split('/')[:3]) + '/yt_downloads'

            options = {
                'format': 'bestaudio/best',
                "keepvideo": False,
                'postprocessors': [{
                    'key': 'FFmpegExtractAudio',
                    'preferredcodec': 'mp3',
                    'preferredquality': '192',
                }],
                'outtmpl': SAVE_PATH + f"/{filename}.%(ext)s",

            }

            with youtube_dl.YoutubeDL(options) as ytdl:
                ytdl.download([video_info["webpage_url"]])

            await ctx.send(file=discord.File(f"yt_downloads/{filename}.mp3"))
Esempio n. 3
0
 async def play_(self, ctx: commands.context.Context, *, url):
     async with ctx.typing():
         player = await YTDLSource.from_url(url,
                                            loop=self.bot.loop,
                                            stream=True)
         ctx.voice_client.play(
             player
         )  # , after=lambda e: print('Player error: %s' % e) if e else None)
         self.players[ctx.guild.id] = ctx.voice_client
     await ctx.send(f"Now playing {player.title}")
Esempio n. 4
0
    async def poe(self, ctx: commands.context.Context, item_name):
        """Look up a PoE Unique.
		Returns an image. "/poe starforge """
        with ctx.typing():
            # 3. Run in a custom process pool:
            with concurrent.futures.ThreadPoolExecutor() as pool:
                img_bytes = await self.bot.loop.run_in_executor(
                    pool, self.build_item_image, item_name)
                msg = DeletableMessage(sql_session=self.sql)
                if not img_bytes:
                    await msg.send(
                        ctx, content="Could not find any matching items!")
                    return
                await msg.send(ctx,
                               file=discord.File(io.BytesIO(img_bytes),
                                                 '%s.png' % item_name))
Esempio n. 5
0
 async def load_user_messages(self,
                              ctx: commands.context.Context,
                              build_user_corpus=True):
     """ Load all User Messages into the DB - this is slow & Admin Only. """
     start = time.time()
     msg: discord.Message = await ctx.send(
         "Rebuilding User text models in Database...")
     found = 0
     sent = [msg]
     async with ctx.typing():
         for guild in self.bot.guilds:
             for ch in guild.text_channels:
                 permission = ch.permissions_for(
                     guild.get_member(self.bot.user.id))
                 if not permission.read_messages:
                     print("Skipping unreadable channel:", ch.name)
                     continue
                 msg = await ctx.send(
                     "Scanning guild: '%s'  ->   Channel: [%s]..." %
                     (guild.name, ch.name))
                 sent.append(msg)
                 print("Scanning guild: %s  ->   Channel: %s" %
                       (guild.name, ch.name))
                 async for message in ch.history(limit=None):
                     if message.author.bot:
                         continue
                     if self.handler.store_user_message(message,
                                                        commit_after=False):
                         found += 1
                         if build_user_corpus:
                             path = UserSimulator.message_to_path(message)
                             self.handler.add_message_corpus(
                                 file_path=path, message=message)
                 print("\t+Finished at:", round(time.time() - start, 2))
     self.sql.commit()
     for msg in sent:
         await msg.delete()
     elapsed = round(time.time() - start, 2)
     await ctx.send(
         "Gathered all User text data. Found %s new messages in %s seconds."
         % (found, elapsed))
Esempio n. 6
0
    async def whoami(self, ctx: commands.context.Context):
        """
        Get information on your linked FFXIV character
        """
        try:
            player = Player.get(Player.discord_id == ctx.author.id)
        except peewee.DoesNotExist:
            await ctx.send(
                f"{ctx.author.mention} You haven't linked your FFXIV account yet! Run the `f.help iam` command for information on how to do this."
            )
            return

        async with ctx.typing():
            try:
                character = await self.xiv.get_character(player.lodestone_id)
            except ValueError as e:
                await ctx.send(str(e))
                return

        await ctx.send(embed=character.embed(
            verified=player.status == Player.STATUS_VERIFIED))
Esempio n. 7
0
    async def whois(self, ctx: commands.context.Context,
                    member: discord.Member):
        """
        Get the specified discord users FFXIV account
        """
        try:
            player = Player.get(Player.discord_id == member.id)
        except peewee.DoesNotExist:
            await ctx.send(
                f"{member.display_name} has not linked their FFXIV account to their Discord profile"
            )
            return

        async with ctx.typing():
            try:
                character = await self.xiv.get_character(player.lodestone_id)
            except ValueError as e:
                await ctx.send(str(e))
                return

        await ctx.send(embed=character.embed(
            verified=player.status == Player.STATUS_VERIFIED))
Esempio n. 8
0
    async def iam(self, ctx: commands.context.Context, world: str, *,
                  character: str):
        """
        Link your FFXIV character to Filo
        """
        if Player.select().where(Player.discord_id == ctx.author.id).count():
            confirm_message = await ctx.send(
                f"{ctx.author.mention} An FFXIV character has already been linked to this Discord account. Are you sure you want to replace it? (Y/N)"
            )
            try:
                response = await self.bot.wait_for('message',
                                                   timeout=15.0,
                                                   check=self._author_check(
                                                       ctx.message.author))
                await response.delete()
                await confirm_message.delete()

                if response.content.lower().strip() not in ('y', 'yes'):
                    return
            except asyncio.TimeoutError:
                await confirm_message.delete()
                return

        try:
            forename, surname = character.lower().split(' ')
            world = world.lower()
        except ValueError:
            await ctx.send(
                'Invalid character name provided. Please provide the world name first, then your characters first and last names. For example, `f.iam Mateus Totomo Omo`',
                delete_after=10.0)
            return

        if world.title() not in HuntManager.WORLDS:
            await ctx.send(
                'Invalid world provided. Please provide the world name first, then your characters first and last names. For example, `f.iam Mateus Totomo Omo`',
                delete_after=10.0)
            return

        async with ctx.typing():
            try:
                Player.delete().where(
                    Player.discord_id == ctx.author.id).execute()
                lodestone_id, character = await self.xiv.search_character(
                    world, forename, surname)
            except ValueError as e:
                await ctx.send(str(e))
                return
            except TypeError:
                self._log.info(
                    "Failed to find character on first query - trying again.")
                try:
                    lodestone_id, character = await self.xiv.search_character(
                        world, forename, surname)
                except TypeError:
                    await ctx.send(
                        f"Unable to find a character by the name of **{character}** on the world **{world.lower().title()}** - Please check your spelling and try again."
                    )
                    return

            try:
                Player.delete().where((Player.lodestone_id == lodestone_id) & (
                    Player.status == Player.STATUS_PENDING)).execute()
                player = Player.create(lodestone_id=lodestone_id,
                                       discord_id=ctx.author.id,
                                       name=character.name,
                                       world=character.server,
                                       validation_code=uuid.uuid4())
            except peewee.IntegrityError:
                await ctx.send(
                    f"{ctx.author.mention} This character has already been linked to another discord user."
                )
                return

            await ctx.send(embed=character.embed())
            await ctx.send(
                f"""{ctx.author.mention} **Note:** Your character has not been validated yet.\n\nTo verify your ownership of this character, please copy and paste the following verification code into your Lodestone Character Profile and then run the `f.verify` command:\n```\n{player.validation_code}\n```\nhttps://na.finalfantasyxiv.com/lodestone/my/setting/profile/"""
            )