Beispiel #1
0
 async def delevent(self, ctx: commands.Context):
     """
     Deletes an event
     #STAFF
     """
     gen = [
         event.name
         for event in self.events
     ]
     multiple_choice = BotMultipleChoice(
         ctx, gen, "Choose which event to delete", colour=0x94F29B)
     await multiple_choice.run()
     await multiple_choice.quit()
     if multiple_choice.choice:
         confirmation = BotConfirmation(ctx, 0x012345)
         await confirmation.confirm(f"Are you sure you want to delete {multiple_choice.choice}?")
         if confirmation.confirmed:
             await confirmation.update("Confirmed", color=0x55ff55)
             async with self.lock:
                 for n, event in enumerate(self.events):
                     if event.name == multiple_choice.choice:
                         self.events[n] = None
                         async with aiosqlite.connect("calendar.db") as db:
                             await db.execute(
                                 """DELETE FROM events WHERE date_start=? AND date_end=? AND name=?""",
                                 (event.date_start, event.date_end, event.name))
                             await db.commit()
                 self.events = [event for event in self.events if event is not None]
         else:
             await confirmation.update("Not confirmed", hide_author=True, color=0xFF0000)
Beispiel #2
0
    async def fuckchoices(self, ctx):
        multiple_choice = BotMultipleChoice(
            ctx, ['one', 'two', 'three', 'four', 'five', 'six'],
            "How many babys would you eat")
        await multiple_choice.run()

        await multiple_choice.quit(multiple_choice.choice)
Beispiel #3
0
 async def delete_availabilities(self, ctx: commands.Context):
     if not self.availabilities:
         await ctx.send(embed=discord.Embed(title='No availabilities have been set!', colour=0xFF0000))
         return
     gen = [
         stamp_to_str(avail.date_start) + " - " + stamp_to_str(avail.date_end)
         for avail in self.availabilities if avail.userid == ctx.author.id
     ]
     multiple_choice = BotMultipleChoice(
         ctx, gen, 'Choose which of your avails to delete',
         colour=0x94F29B)
     await multiple_choice.run()
     await multiple_choice.quit()
     if multiple_choice.choice:
         confirmation = BotConfirmation(ctx, 0x012345)
         await confirmation.confirm(f"Are you sure you want to delete {multiple_choice.choice}?")
         if confirmation.confirmed:
             await confirmation.update("Confirmed", color=0x55ff55)
             async with self.lock:
                 for n, avail in enumerate(self.availabilities):
                     if (stamp_to_str(avail.date_start) + " - " + stamp_to_str(avail.date_end) ==
                             multiple_choice.choice and avail.userid == ctx.author.id):
                         self.availabilities[n] = None
                         async with aiosqlite.connect("calendar.db") as db:
                             await db.execute(
                                 """DELETE FROM availabilities WHERE userid=? AND date_start=? AND date_end=?""",
                                 (ctx.author.id, avail.date_start, avail.date_end))
                             await db.commit()
                 self.availabilities = [avail for avail in self.availabilities if avail is not None]
         else:
             await confirmation.update("Not confirmed", hide_author=True, color=0xFF0000)
Beispiel #4
0
 async def view_availabilities(self, ctx: commands.Context):
     """
     View all availabilities or the ones for a specific user
     """
     if not self.availabilities:
         await ctx.send(embed=discord.Embed(
             title='No availabilities have been set!', colour=0xFF0000))
         return
     choice_list = list(
         set([
             ctx.guild.get_member(avail.userid).display_name
             for avail in self.availabilities
         ]))
     multiple_choice = BotMultipleChoice(
         ctx,
         choice_list,
         "Choose a user to view availabilities for",
         colour=0x94F29B)
     await multiple_choice.run()
     await multiple_choice.quit()
     e_avails = discord.Embed(
         title=f'{multiple_choice.choice}\'s availabilities',
         colour=0x94F29B)
     if multiple_choice.choice:
         for avail in self.availabilities:
             if ctx.guild.get_member(
                     avail.userid).display_name == multiple_choice.choice:
                 e_avails.add_field(
                     name=f'Start: {stamp_to_str(avail.date_start)}',
                     value=f'**End: {stamp_to_str(avail.date_end)}**')
         await ctx.send(embed=e_avails)
Beispiel #5
0
async def choice(ctx, user):
    choice = BotMultipleChoice(ctx, ["Heads", "Tails"],
                               f"{user.display_name}'s Coin Flip",
                               closeable=False)
    res = await choice.run([user])
    await res[1].delete()
    if res[0] == "Heads":
        return 1
    else:
        return 0
Beispiel #6
0
    async def rps(self, ctx):
        PlayerScore = 0
        BotScore = 0
        while True:
            player = BotMultipleChoice(ctx, ['剪刀', '石頭', '布'], "請出拳")
            await player.run()
            await player.quit()
            bot = random.choice(['剪刀', '石頭', '布'])
            if player.choice == '剪刀':
                if bot == '剪刀':
                    status = '平手'
                if bot == '石頭':
                    status = '失敗'
                if bot == '布':
                    status = '勝利'
            elif player.choice == '石頭':
                if bot == '剪刀':
                    status = '勝利'
                if bot == '石頭':
                    status = '平手'
                if bot == '布':
                    status = '失敗'
            elif player.choice == '布':
                if bot == '剪刀':
                    status = '失敗'
                if bot == '石頭':
                    status = '勝利'
                if bot == '布':
                    status = '平手'
            else:
                embed = discord.Embed(title="已取消", color=discord.Colour.red())
                await ctx.send(embed=embed)
                break

            if status == '失敗':
                BotScore += 1
                color = discord.Colour.red()
            if status == '勝利':
                PlayerScore += 1
                color = discord.Colour.green()
            if status == '平手':
                color = discord.Colour.orange()

            confirm = BotConfirmation(ctx, color)
            await confirm.confirm(
                f"__**{status}**__\n{player.choice} vs {bot}\n{PlayerScore} | {BotScore}\n繼續?"
            )

            if confirm.confirmed:
                await confirm.quit()
                continue
            else:
                break
Beispiel #7
0
 async def poll(self, ctx, *, desired_questions: str = None):
     if desired_questions is None:
         await ctx.send(embed=errorhandler.BotAlert(
             "warn",
             "What do you want a poll about? Syntax: Question, options, separated, by, commas",
         ))
         return
     self.split_questions = desired_questions.split(",")
     self.question = self.split_questions[0]
     self.split_questions.pop(0)
     try:
         self.poll_verify = poll.PollHelper(
             self.split_questions).verify_poll()
     except poll.PollException:
         await ctx.send(embed=errorhandler.BotAlert(
             "error", "Limit exeded").get_error_embed())
         return
     self.multiple_choice = BotMultipleChoice(ctx, self.split_questions,
                                              self.question)
     await self.multiple_choice.run()
Beispiel #8
0
 async def deleteadmincoords(self, ctx: commands.Context):
     """
     **ADMIN ONLY**
     Deletes the admin coords selected from the multiple choice
     """
     await ctx.message.delete()
     deladmin_gen = [(adm.name, ) for adm in self.admincoords
                     if adm.guild_id == ctx.guild.id]
     async with aiosqlite.connect("coorddata.db") as db:
         multiple_choice = BotMultipleChoice(
             ctx, [tup[0] for tup in deladmin_gen],
             "Select the coords you wish to delete",
             colour=0xFFAE00)
         await multiple_choice.run()
         await multiple_choice.quit()
         confirmation = BotConfirmation(ctx, 0xFFAE00)
         if multiple_choice.choice:
             await confirmation.confirm("Are you sure?")
             if confirmation.confirmed:
                 for adm in self.admincoords:
                     if adm.name == multiple_choice.choice and adm.guild_id == ctx.guild.id:
                         self.admincoords.remove(adm)
                 await db.execute(
                     """DELETE FROM admincoords WHERE name=? AND guild_id=?""",
                     (
                         multiple_choice.choice,
                         ctx.guild.id,
                     ))
                 await db.commit()
                 embed_del = discord.Embed(
                     title=
                     f'Admin coords for {multiple_choice.choice} deleted',
                     description=f'Deleted by {ctx.author.display_name}',
                     colour=0xFF0000)
                 await ctx.send(embed=embed_del)
             else:
                 await confirmation.update("Not confirmed",
                                           hide_author=True,
                                           color=0xff5555)
Beispiel #9
0
    async def choice(self, ctx):
        multiple_choice = BotMultipleChoice(ctx, ['one', 'two', 'three', 'four', 'five', 'six'], "Testing stuff")
        await multiple_choice.run()

        await multiple_choice.quit(multiple_choice.choice)
Beispiel #10
0
    async def delshop(self,
                      ctx: commands.Context,
                      user: discord.Member = None):
        """
        Deletes the shops that the user chooses from the multiple choice embed
        **ADMIN ONLY**:
        Do `$delshop <@user>` to delete shops for that user
        """
        await ctx.message.delete()
        if user:
            if ('administrator', True) not in ctx.author.guild_permissions:
                await ctx.send(embed=discord.Embed(
                    title="You don't have the administrator permission!"))
                return
            delshops_gen = [
                shop.name for shop in self.usercoords
                if shop.user_id == user.id and shop.guild_id == ctx.guild.id
            ]
            if not delshops_gen:
                await ctx.send(embed=discord.Embed(
                    title="This user doesn't have any registered shops",
                    colour=0xFF0000))
                return
            confirmation = BotConfirmation(ctx, 0xFFAE00)
            multiple_choice = BotMultipleChoice(
                ctx,
                delshops_gen + ['Delete all shops'],
                "Select the coordinates you wish to delete",
                colour=0xFFAE00)
            await multiple_choice.run()
            await multiple_choice.quit()
            async with aiosqlite.connect("coorddata.db") as db:
                if multiple_choice.choice == 'Delete all shops':
                    await confirmation.confirm(
                        "Are you sure you want to delete all shops for this user?"
                    )
                    if confirmation.confirmed:
                        await confirmation.update("Confirmed", color=0xFFAE00)
                        await db.execute(
                            "DELETE FROM shops WHERE guild_id=? AND user_id=?",
                            (ctx.guild.id, user.id))
                        await db.commit()
                        for shop in self.shops:
                            if shop.user_id == user.id and shop.guild_id == ctx.guild.id:
                                self.usercoords.remove(shop)
                        embed_delete = discord.Embed(
                            title=f"All of {user.display_name}'s shops deleted",
                            colour=0xFFAE00)
                        await ctx.send(embed=embed_delete)
                    else:
                        await confirmation.update("Not confirmed",
                                                  hide_author=True,
                                                  color=0xFF0000)

                elif multiple_choice.choice:
                    await confirmation.confirm(
                        f"Are you sure you want to delete {multiple_choice.choice}?"
                    )
                    if confirmation.confirmed:
                        await confirmation.update(
                            f"{user.display_name}'s ({multiple_choice.choice}) shop deleted",
                            color=0xFFAE00)
                        await db.execute(
                            "DELETE FROM shops WHERE guild_id=? AND user_id=? AND name=?",
                            (ctx.guild.id, user.id, multiple_choice.choice))
                        await db.commit()
                        for shop in self.shops:
                            if (shop.name == multiple_choice.choice
                                    and shop.user_id == user.id
                                    and shop.guild_id == ctx.guild.id):
                                self.usercoords.remove(shop)
                    else:
                        await confirmation.update("Not confirmed",
                                                  hide_author=True,
                                                  color=0xFF0000)
        else:
            author_shops = [
                shop.name for shop in self.shops if
                shop.user_id == ctx.author.id and shop.guild_id == ctx.guild.id
            ]
            if not author_shops:
                await ctx.send(embed=discord.Embed(
                    title='You have no shops set!', colour=0xFF0000))
                return
            multiple_choice = BotMultipleChoice(
                ctx,
                author_shops,
                "Select the shop you wish to delete",
                colour=0xFFAE00)
            await multiple_choice.run()
            await multiple_choice.quit()
            if multiple_choice.choice:
                confirmation = BotConfirmation(ctx, 0xFFAE00)
                await confirmation.confirm(
                    f"Are you sure you want to delete {multiple_choice.choice}?"
                )
                if confirmation.confirmed:
                    for shop in self.shops:
                        if (shop.name == multiple_choice.choice
                                and shop.guild_id == ctx.guild.id
                                and shop.user_id == ctx.author.id):
                            self.shops.remove(shop)
                    async with aiosqlite.connect("coorddata.db") as db:
                        await db.execute(
                            """DELETE FROM shops WHERE user_id=? AND name=? AND guild_id=?""",
                            (ctx.author.id, multiple_choice.choice,
                             ctx.guild.id))
                        await db.commit()
                        await confirmation.update(
                            f"Your shop: ({multiple_choice.choice}) has been deleted",
                            color=0xFFAE00)
                else:
                    await confirmation.update("Not confirmed",
                                              hide_author=True,
                                              color=0xFF0000)
Beispiel #11
0
async def hypixel(
        ctx: SlashContext,
        player: str,  # noqa C901
        bot: ansura.AnsuraBot,
        token: str,
        profile_type: str = None):
    if profile_type and len(profile_type.split(" ")) > 1:
        return
    await ctx.defer()
    data = await _get(player, token)
    if data["player"] is None:
        await ctx.reply("That player doesn't seem to exist on hypixel.")
        return

    player = data["player"]
    player_name = player["displayname"]

    e = _mk_embed(player_name, profile_type if profile_type else None)
    profile_type = profile_type.lower() if profile_type else profile_type

    if profile_type == "profile":
        e.add_field(name="Previous Names",
                    value=_("\n".join(player["knownAliases"])))
        if "mcVersionRp" in player.keys():
            e.add_field(name="Minecraft Version",
                        value=_(player["mcVersionRp"]))
            # .strftime("%x %X")
        tz = pytz.timezone("America/Winnipeg")
        time = tz.localize(datetime.fromtimestamp(player["lastLogout"] / 1000))
        player_tz = bot.db.lookup_timezone(ctx.author.id)[1]
        timel = time.astimezone(
            pytz.timezone(player_tz)) if player_tz else None
        #
        e.add_field(
            name="Last Seen",
            value=f"{time.strftime('%x %X')}"
            f" (Server)\n{timel.strftime('%x %X') if timel else 'N/A'} (Local)"
            if player["lastLogout"] > player["lastLogin"] else "Now")
        e.add_field(name="Hypixel Level",
                    value=f"{await _get_level(exp=player['networkExp'])}")

    elif profile_type == "bedwars":
        player_bw = player["stats"]["Bedwars"]
        prefixes = {
            "2v2": "eight_two",
            "3v3v3v3": "four_three",
            "4v4v4v4": "four_four",
            "4v4": "two_four"
        }
        s = "```"
        s += f"Level {player['achievements']['bedwars_level']}\n"
        for _prefix in prefixes:
            w = player_bw.get(f"{prefixes[_prefix]}_wins_bedwars", 0)
            loss = player_bw.get(f"{prefixes[_prefix]}_losses_bedwars", 0)
            fk = player_bw.get(f"{prefixes[_prefix]}_final_kills_bedwars", 0)
            k = player_bw.get(f"{prefixes[_prefix]}_kills_bedwars", 0)
            d = player_bw.get(f"{prefixes[_prefix]}_deaths_bedwars", 0)
            s += _prefix.center(13, "=") + "\n"
            s += f"{w}/{w + loss} Won\n"
            s += f"{k}:{d} KDR ({round(k / d, 2)}\n"
            s += f"({fk} Final Kills)\n"

        e.description = s + "```"

    elif profile_type == "skywars":
        player = player["stats"]["SkyWars"]
        prefixes = {
            "Solo": "solo",
            "Solo Normal": "solo_normal",
            "Solo Insane": "solo_insane",
            "Teams": "team",
            "Teams Normal": "teams_normal",
            "Teams Insane": "teams_insane"
        }
        results = []
        for _prefix in prefixes:
            s = [_prefix]
            vk = player.get(f'void_kills_{prefixes[_prefix]}', "-")
            w = player.get(f'wins_{prefixes[_prefix]}', "-")
            g = player.get(f'games_{prefixes[_prefix]}', "-")
            k = player.get(f'kills_{prefixes[_prefix]}', "-")
            d = player.get(f'deaths_{prefixes[_prefix]}', "-")
            s.append(f"{w}/{g} Won".ljust(21, " "))
            s.append(
                f"{k}:{d} KDR ({round(k / d, 2) if '-' not in [k, d] else ''})"
                .ljust(21, " "))
            s.append(f"{vk} Void kills".ljust(21, " "))
            results.append(s)

        e.description = ""
        for r in results:
            e.add_field(name=r[0], value="```" + "\n".join(r[1:4]) + "```")

    elif profile_type == "uhc":
        player = player["stats"]["UHC"]
        e.description = "```" \
                        f"{player.get('kills', 0)} K\n" \
                        f"{player.get('deaths', 0)} D" \
                        "```"

    elif profile_type == "skyblock":
        player = player["stats"]["SkyBlock"]["profiles"]
        profile_id = None
        profiles = []
        for i in player.values():
            profiles.append((i["profile_id"], i["cute_name"]))
        mult_choice = BotMultipleChoice(
            ctx, [profile["cute_name"] for profile in player.values()],
            "Choose a SkyBlock profile")
        await mult_choice.run()
        await mult_choice.quit()
        if mult_choice.choice:
            for i in profiles:
                if i[1] == mult_choice.choice:
                    profile_id = i[0]
                    break
        else:
            return
        async with aiohttp.ClientSession() as sess:
            if profile_id:
                async with sess.get(
                        f"https://api.hypixel.net/skyblock/profile?key={token}&profile={profile_id}"
                ) as resp:
                    data2 = await resp.json()
        profile = data2["profile"]
        player_sb_id = data["player"]["uuid"]
        player_sb = profile["members"][player_sb_id]
        if "slayer_bosses" in player_sb:
            e.add_field(name="Slayers",
                        value="\n".join([
                            f"{k.title()}:"
                            f" {_slayer_level(v.get('xp', 0), k)}"
                            for k, v in player_sb["slayer_bosses"].items()
                        ]))
            e.add_field(
                name="Money",
                value=
                f"Bank: {round(float(profile.get('banking', {'balance': 0})['balance']), 1)} Coins\n"
                f"Purse: {round(float(player_sb['coin_purse']), 1)} Coins")
        skills_list = await _get_level(player_name, profile_id)
        e.add_field(name="Experience",
                    value="\n".join(
                        [f"{tup[0]}: {tup[1]}" for tup in skills_list]))
        e.add_field(
            name="Misc",
            value=f"Fairy Souls: {player_sb.get('fairy_souls_collected', 0)}\n"
        )
        e.set_footer(
            text=
            "If skills/exp appear as 0, you may not have API visibility on for your"
            " Skyblock profile.")
    elif profile_type in ["raw"]:
        e.description = await _raw(data)

    await ctx.reply(embeds=[e])
Beispiel #12
0
async def work(ctx):
    from disputils import BotEmbedPaginator, BotConfirmation, BotMultipleChoice
    multiple_choice = BotMultipleChoice(
        ctx, ['Policeman', 'Builder', 'Banker', 'Soldier', 'Doctor'],
        "What job would you like to do?")
    await multiple_choice.run()

    await multiple_choice.quit()
    multiple_choice.choice
    reactions = {
        'Policeman': '👮',
        'Builder': '👷',
        'Banker': '🏦',
        'Soldier': '🎖️',
        'Doctor': '⛑️'
    }
    channel = ctx.message.channel
    await open_account(ctx.author)
    embed = discord.Embed()
    embed.add_field(
        name=f'Work for {multiple_choice.choice}',
        value=
        f'React with {reactions[multiple_choice.choice]} to recieve your money!'
    )
    await ctx.send(embed=embed)
    users = await get_bank_data()

    def check(reaction, user):
        #print(str(reaction.emoji))
        #print(str(reaction.emoji))
        return user == ctx.message.author and str(
            reaction.emoji) == reactions[multiple_choice.choice]

    job1_earnings = random.randint(0, 5000)
    try:
        #await channel.send(f'{str(reaction.emoji)}')
        await bot.wait_for('reaction_add', timeout=60.0, check=check)
    except asyncio.TimeoutError:
        await asyncio.sleep(1)
        await channel.send('Your employer was busy and had to go')
    else:
        a = []
        # for i in range(200):
        #     a.append('Alive')
        a.append('Dead')
        if random.choice(a) == 'Dead':
            b = random.randint(-50000, -1000)
            users[str(ctx.author.id)]['wallet'] += b
            embed1 = discord.Embed(
                title='Sadly',
                description=
                f'You died, and lost {b} <a:IBEgetMoney:780141666261663755>')
            await channel.send(embed=embed1)
            return
        await asyncio.sleep(1)
        embed1 = discord.Embed(
            title='Success',
            description=
            f'Well done! You earned `{job1_earnings}` <a:IBEgetMoney:780141666261663755> .Your employer = `{multiple_choice.choice}`'
        )
        await channel.send(embed=embed1)
        users[str(ctx.author.id)]['wallet'] += job1_earnings

    with open('bank.json', 'w') as f:
        json.dump(users, f)
Beispiel #13
0
async def choice(ctx):
    multiple_choice = BotMultipleChoice(
        ctx, ["one", "two", "three", "four", "five", "six"], "Testing stuff")
    await multiple_choice.run()

    await multiple_choice.quit(multiple_choice.choice)