예제 #1
0
    async def on_member_join(self, member):
        karma.user_add_karma(member.id, 1)

        member_created_at_date = str(member.created_at).split('.', 1)[0]
        avatar = member.avatar_url if member.avatar else member.default_avatar_url

        embed = discord.Embed(color=settings.embed_color)
        embed.set_author(name="{} joined the server! 🎉".format(member.name))
        embed.add_field(name="Username:"******"{}#{}".format(member.name,
                                             member.discriminator),
                        inline=False)
        embed.add_field(name="Time Joined:",
                        value=curtime.get_time(),
                        inline=False)
        embed.add_field(name="Account Created at:",
                        value=member_created_at_date,
                        inline=False)
        embed.add_field(name="User Avatar URL", value=member.avatar_url)
        embed.set_thumbnail(url=avatar)
        embed.set_footer(
            text="We now have {} members!".format(member.guild.member_count))
        channel = self.client.get_channel(id=settings.notification_channel)
        await channel.send(embed=embed)

        await member.send(
            "Thank you for joining the server! **After reading the rules** in <#{}> type `.accept` in the channel to "
            "gain access to other channels, or `.decline` if you don't agree with the terms"
            .format(settings.accept_channel))
예제 #2
0
    async def on_raw_reaction_add(self, payload):
        if int(payload.channel_id) == settings.game_channel:
            guild = self.client.get_guild(payload.guild_id)
            user = guild.get_member(payload.user_id)
            reaction = payload.emoji.name

            if int(payload.message_id) == settings.groups_message_id:
                if str(reaction) == '🇦':
                    await user.add_roles(code)
                if str(reaction) == '🇧':
                    await user.add_roles(poker)
                if str(reaction) == '🇨':
                    await user.add_roles(snowboard)
                    karma.user_add_karma(user, -100)

            if int(payload.message_id) == settings.games_message_id:
                if str(reaction) == '🇦':
                    if payload.user_id != 262677178590822400:
                        await user.add_roles(league)
                if str(reaction) == '🇧':
                    if payload.user_id != 262677178590822400:
                        await user.add_roles(hs)
                if str(reaction) == '🇨':
                    await user.add_roles(fortnite)
                if str(reaction) == '🇩':
                    await user.add_roles(pubg)
                if str(reaction) == '🇪':
                    if payload.user_id != 262677178590822400:
                        await user.add_roles(tf2)
                if str(reaction) == '🇫':
                    await user.add_roles(gta)
                if str(reaction) == '🇬':
                    await user.add_roles(chiv)
                if str(reaction) == '🇭':
                    await user.add_roles(cs)
                if str(reaction) == '🇮':
                    if payload.user_id != 262677178590822400:
                        await user.add_roles(aoe)
                if str(reaction) == '🇯':
                    if payload.user_id != 262677178590822400:
                        await user.add_roles(civ)
                if str(reaction) == '🇰':
                    if payload.user_id != 262677178590822400:
                        await user.add_roles(rainbow)
                if str(reaction) == '🇱':
                    if payload.user_id != 262677178590822400:
                        await user.add_roles(brawl)
                if str(reaction) == '🇲':
                    await user.add_roles(ratz)
                if str(reaction) == '🇳':
                    await user.add_roles(skribble)
                if str(reaction) == '🇴':
                    await user.add_roles(gmod)
예제 #3
0
    async def tradekarma(self, ctx, target: discord.Member, amount: int):
        if amount < 0:
            await ctx.send("You cannot give negative karma")
            return

        if amount > karma.get_karma(ctx.author.id):
            await ctx.send("You cannot trade more karma than you have")
            return

        karma.user_add_karma(target.id, amount)
        karma.user_add_karma(ctx.author.id, -amount)
        await ctx.message.channel.send(
            "You traded <@{}> `{}` karma. They now have a total of `{}` karma and you have `{}`"
            .format(target.id, amount, karma.get_karma(target.id),
                    karma.get_karma(ctx.author.id)))
예제 #4
0
async def on_member_join(member):
    for guild in client.guilds:
        for invite in await guild.invites():
            x = [invite.url, invite.uses, invite.inviter.id]
            after_invites.append(x)

        await asyncio.sleep(1)

        def diff(first, second):
            second = list(second)
            return [item for item in first if item not in second]

        invite_used = diff(after_invites, before_invites)
        invite_user = client.get_user(invite_used[0][2])

        if member.guild.name != "Bot Test":
            karma.user_add_karma(invite_user.id, 75)
            channel = client.get_channel(id=settings.notification_channel)
            await channel.send(
                "<@{}> used an invited created by <@{}> which gave the invite creator `75` karma"
                .format(member.id, invite_user.id))
예제 #5
0
    async def roulette(self, ctx, outcome: str, *amount):
        if "outcome" in outcome:
            with open('roulette_outcomes.json', 'r') as fp:
                outcomes = json.load(fp)
            odd_total = outcomes['odd']
            even_total = outcomes['even']
            zero_total = outcomes['zero']
            total_total = outcomes['total']

            outcomes_list = [odd_total, even_total, zero_total]
            total = sum(outcomes_list)
            embed = discord.Embed(color=settings.embed_color)
            embed.set_author(name="Roulette Outcomes 📊")
            embed.add_field(name="Total number of times 'spun'",
                            value=total,
                            inline=True)
            embed.add_field(name="Total Karma Bet",
                            value=total_total,
                            inline=False)
            embed.add_field(name="Odd", value=odd_total, inline=True)
            embed.add_field(name="Even", value=even_total, inline=True)
            embed.add_field(name="Zero", value=zero_total, inline=True)
            await ctx.message.channel.send(embed=embed)
            return

        outcomes = ['odd', 'even', 'zero']
        if outcome not in outcomes:
            print("1" + outcome)
            await ctx.message.channel.send(
                "You need to format your message such as \n`.roulette [odd/even/zero] [amount of karma between 10 and 250]`"
            )
            return
        try:
            amount = int("".join(amount))
        except ValueError:
            await ctx.message.channel.send(
                "You need to format your message such as \n`.roulette [odd/even/zero] [amount of karma 10 and 250]`"
            )

        if 10 > amount or 250 < amount:
            await ctx.message.channel.send(
                "You need to format your message such as \n`.roulette [odd/even/zero] [amount of karma 10 and 250]`"
            )
            return

        if amount > karma.get_karma(ctx.message.author.id):
            await ctx.message.channel.send(
                "You only have `{}` karma available for betting".format(
                    karma.get_karma(ctx.message.author.id)))
            return

        with open('roulette_outcomes.json', 'r') as fp:
            outcomes = json.load(fp)
        outcomes['total'] += amount
        with open('roulette_outcomes.json', 'w') as fp:
            json.dump(outcomes, fp, sort_keys=True, indent=4)

        karma.user_add_karma(ctx.message.author.id, -amount)

        spin = random.randint(0, 36)

        msg = await ctx.message.channel.send("It landed on `{}`!".format(spin))

        if spin == 0:
            await msg.pin()
            if outcome == "zero":
                karma.user_add_karma(ctx.message.author.id, amount * 14)
                await ctx.message.channel.send(
                    "You won! :tada:\nYour new karma total is `{}`".format(
                        karma.get_karma(ctx.message.author.id)))
            else:
                await ctx.message.channel.send(
                    "You lost!\nYour new karma total is `{}`".format(
                        karma.get_karma(ctx.message.author.id)))

            return
        if spin % 2 == 0:
            real_outcome = "even"
        else:
            real_outcome = "odd"
        with open('roulette_outcomes.json', 'r') as fp:
            outcomes = json.load(fp)
        outcomes[real_outcome] += 1
        with open('roulette_outcomes.json', 'w') as fp:
            json.dump(outcomes, fp, sort_keys=True, indent=4)

        if real_outcome == outcome:
            karma.user_add_karma(ctx.message.author.id, amount * 2)
            await ctx.message.channel.send(
                "You won! :tada:\nYour new karma total is `{}`".format(
                    karma.get_karma(ctx.message.author.id)))
        else:
            await ctx.message.channel.send(
                "You lost!\nYour new karma total is `{}`".format(
                    karma.get_karma(ctx.message.author.id)))
예제 #6
0
 async def givekarma(self, ctx, target: discord.Member, amount: int):
     karma.user_add_karma(target.id, amount)
     await ctx.message.channel.send(
         "You gave <@{}> `{}` karma. They now have a total of `{}` karma".
         format(target.id, amount, karma.get_karma(target.id)))
예제 #7
0
    async def on_message(self, message):
        # Message author variables
        user_id = message.author.id
        user_name = message.author

        author_level = karma.get_level(user_id)
        author_karma = karma.get_karma(user_id)

        if message.server and message.author.roles:
            if settings.verified_role_id in [role.id for role in message.author.roles]:
                # UD Code
                if message.content.upper().startswith(".UD"):
                    target_def = message.content[4:]
                    target_def_link_format = target_def.replace(" ", "%20")

                    if "MAGGIE" in message.content.upper():  # Hey don't worry about these couple of lines
                        print("{0}: {1}  requested the UD for Maggie".format(curtime.get_time(), user_name))
                        embed = discord.Embed(title="Definition Page", url="https://goo.gl/j2DX9N", color=settings.embed_color)
                        embed.set_author(name="Definition for Maggie", url="https://goo.gl/j2DX9N")
                        embed.add_field(name="Definition 📚", value="Girl with YUUUG milkers. Doesnt need a coat",
                                        inline=False)
                        embed.add_field(name="Example 💬",
                                        value="Maggie's got such big fun-fun milk bags, she doesn't need a coat! "
                                              "-Aidan Witkovsky 2018",
                                        inline=True)
                        await self.client.send_message(message.channel, embed=embed)
                    else:
                        try:
                            term = udtop(target_def)
                            print("{0}: {1} requested the UD for {2}".format(curtime.get_time(), user_name, target_def))
                            embed = discord.Embed(title="Definition Page", color=settings.embed_color)
                            embed.set_author(name="Definition for {}".format(string.capwords(target_def)))
                            embed.add_field(name="Definition 📚", value=term.definition[:1024], inline=False)
                            embed.add_field(name="Example 💬", value=term.example[:1024], inline=True)
                            await self.client.send_message(message.channel, embed=embed)
                        except (IndexError, AttributeError) as error:
                            await self.client.send_message(message.channel,
                                                           "ERROR `{}`\nSorry, that word doesn't have a definition :( "
                                                           ". You can add your own here: ".format(error))
                            await self.client.send_message(
                                message.channel,
                                "https://www.urbandictionary.com/add.php?word=" + target_def_link_format)

                # 8Ball Code
                if message.content.upper().startswith(".ZALGO "):
                    target = message.content[7:]
                    intensity = {"up": 10, "mid": 10, "down": 10}
                    await self.client.send_message(message.channel, zalgo.zalgo(target, intensity))

                # 8Ball Code
                if message.content.upper().startswith(".8BALL"):
                    print("{0}: {1} requested '.8BALL'".format(curtime.get_time(), user_name))

                    def get_answer(answer_number):
                        if answer_number == 1:
                            return "It is certain"
                        elif answer_number == 2:
                            return "It is decidedly so"
                        elif answer_number == 3:
                            return "Yes"
                        elif answer_number == 4:
                            return "Reply hazy try again"
                        elif answer_number == 5:
                            return "Ask again later"
                        elif answer_number == 6:
                            return "Concentrate and ask again"
                        elif answer_number == 7:
                            return "My reply is **no**"
                        elif answer_number == 8:
                            return "Outlook not so good"
                        elif answer_number == 9:
                            return "Very doubtful"

                    r = random.randint(1, 9)
                    fortune = get_answer(r)
                    await self.client.send_message(message.channel, fortune)

                # Uptime Code
                if message.content.upper().startswith(".UPTIME"):
                    print("{0}: {1} requested '.UPTIME'".format(curtime.get_time(), user_name))

                    await self.client.send_message(message.channel, "The bot has been live for `{}` {}".format(
                        curtime.uptime(), random.choice(clock_emoji)))

                # Gets random bear picture
                if message.content.upper().startswith(".BEAR"):
                    print("{0}: {1} sent a bear".format(curtime.get_time(), user_name))
                    fp = random.choice(os.listdir("media/bears"))
                    await self.client.send_file(message.channel, "media/bears/{}".format(fp))

                # Gets random Sam picture
                if message.content.upper().startswith(".SAM"):
                    print("{0}: {1} sent a sam".format(curtime.get_time(), user_name))
                    fp = random.choice(os.listdir("media/sams"))
                    await self.client.send_file(message.channel, "media/sams/{}".format(fp))

                # Gets random Apu picture
                if message.content.upper().startswith(".APU"):
                    print("{0}: {1} sent a apu".format(curtime.get_time(), user_name))
                    fp = random.choice(os.listdir("media/apus"))
                    await self.client.send_file(message.channel, "media/apus/{}".format(fp))

                if message.content.upper() == ".CAT":
                    search = "https://nekos.life/api/v2/img/meow"
                    async with self.session.get(search) as r:
                        result = await r.json()
                    await self.client.send_message(message.channel, result['url'])

                if message.content.upper() == ".DOG":
                    search = "https://dog.ceo/api/breeds/image/random"
                    async with self.session.get(search) as r:
                        result = await r.json()
                    await self.client.send_message(message.channel, result['message'])

                # Server Info
                if message.content.upper().startswith(".SERVERINFO"):
                    print("{0}: {1} requested '.SERVER'".format(curtime.get_time(), user_name))
                    online = 0
                    for i in message.server.members:
                        if str(i.status) == "online" or str(i.status) == "idle" or str(i.status) == "dnd":
                            online += 1

                    role_count = len(message.server.roles)
                    emoji_count = len(message.server.emojis)
                    server_created_time = message.server.created_at

                    print("{0}: {1} activated the SERVER command".format(curtime.get_time(), user_name))
                    em = discord.Embed(color=settings.embed_color)
                    em.set_author(name="Server Info:")
                    em.add_field(name="Server Name:", value=message.server.name)
                    em.add_field(name="Server ID:", value=message.server.id)
                    em.add_field(name="Owner:", value=message.server.owner, inline=False)
                    em.add_field(name="Members:", value=message.server.member_count)
                    em.add_field(name="Members Online:", value=online)
                    # em.add_field(name="Text Channels", value=str(channel_count))
                    em.add_field(name="Region:", value=message.server.region)
                    em.add_field(name="Verification Level:", value=str(message.server.verification_level).capitalize())
                    em.add_field(name="Highest Ranking Role:", value=message.server.role_hierarchy[0])
                    em.add_field(name="Number of Roles:", value=str(role_count))
                    em.add_field(name="Custom Emotes:", value=str(emoji_count))
                    em.add_field(name="Time Created:", value=str(server_created_time)[:10])
                    em.add_field(name="Default Channel:", value=message.server.default_channel)
                    em.add_field(name="AFK Time:", value="{} seconds".format(message.server.afk_timeout))
                    em.add_field(name="AFK Channel:", value=message.server.afk_channel)
                    em.add_field(name="Voice Client:", value=message.server.voice_client)
                    em.add_field(name="Icon URL", value=message.server.icon_url)
                    em.set_thumbnail(url=message.server.icon_url)
                    em.set_author(name="\u200b")
                    await self.client.send_message(message.channel, embed=em)

                # TODO Fix this
                # Gives Server Emojis
                if message.content.upper().startswith(".EMOTES"):
                    print("{0}: {1} activated the EMOTES command".format(curtime.get_time(), user_name))
                    emojis = [str(x) for x in message.server.emojis]
                    emojis_str = "> <".join(emojis)
                    await self.client.send_message(message.channel, emojis_str)

                    # Gives link to beta testing server
                if message.content.upper().startswith(".BETA"):
                    print("{0}: {1} activated the BETA command".format(curtime.get_time(), user_name))
                    user = await self.client.get_user_info(user_id)
                    await self.client.send_message(message.channel,
                                                   "Hey <@!196355904503939073>, <@{}> wants beta access.\nType"
                                                   " `.allow` to send them an invite".format(user_id))
                    msg = await self.client.wait_for_message(content=".allow")
                    if msg is None:
                        await self.client.send_message(
                            message.channel,
                            "<@!196355904503939073> didn't respond in time :(. Please try another time.")
                    else:
                        if msg.author.id == "196355904503939073":  # My Discord ID
                            testinvite = settings.get_json('./test_server.json')
                            invite = testinvite.get("invite")
                            await self.client.send_message(user, "You've been accepted! {}".format(invite))
                            await self.client.send_message(message.channel,
                                                           "<@{}> was accepted into the beta testing server! "
                                                           ":tada:".format(user_id))
                        else:
                            await self.client.send_message(message.channel, "You can't do that!")

                if message.content.upper().startswith(".DMME"):
                    user = await self.client.get_user_info(user_id)
                    await self.client.send_message(user, "DM")

                if message.content.upper().startswith(".COPYPASTA"):
                    c = 0
                    while c != 1:
                        search = "https://www.reddit.com/r/copypasta/random/.json?limit=1"
                        async with self.session.get("{}?limit=1".format(search)) as r:
                            result = await r.json()
                        if result[0]['data']['children'][0]['data']['author'] == "AutoModerator" or result[0]['data']['children'][0]['data']['pinned'] == "false":
                            print("Post was automodpost, skipping")
                            pass
                        else:
                            c = 1

                    embed = discord.Embed(
                        title=str(result[0]['data']['children'][0]['data']['title'])[:256],
                        color=settings.embed_color, description="[View Post]({})\n {}".format(
                            str(result[0]['data']['children'][0]['data']['url']),
                            str(result[0]['data']['children'][0]['data']['selftext'])[:1800]))

                    if '.redd.it' or 'imgur' in result[0]['data']['children'][0]['data']['url']:
                        embed.set_image(url=result[0]['data']['children'][0]['data']['url'])

                    if len(result[0]['data']['children'][0]['data']['selftext']) > 1800:
                        embed.set_footer(text="This post was too long to fit. Full version can be found via the 'View "
                                              "Post' button above")

                    await self.client.send_message(message.channel, embed=embed)

                if message.content.upper().startswith(".EMOJIPASTA"):
                    c = 0
                    while c != 1:
                        search = "https://www.reddit.com/r/emojipasta/random/.json?limit=1"
                        async with self.session.get("{}?limit=1".format(search)) as r:
                            result = await r.json()
                        if result[0]['data']['children'][0]['data']['author'] == "AutoModerator" or result[0]['data']['children'][0]['data']['pinned'] == "false":
                            print("Post was automodpost, skipping")
                            pass
                        else:
                            c = 1

                    embed = discord.Embed(
                        title=str(result[0]['data']['children'][0]['data']['title'])[:256],
                        color=settings.embed_color, description="[View Post]({})\n {}".format(
                            str(result[0]['data']['children'][0]['data']['url']),
                            str(result[0]['data']['children'][0]['data']['selftext'])[:1800]))

                    try:
                        # if '.redd.it' or 'imgur' in result[0]['data']['children'][0]['data']['url']:
                        embed.set_image(url=result[0]['data']['children'][0]['data']['url'])
                    except:
                        pass

                    if len(result[0]['data']['children'][0]['data']['selftext']) > 1800:
                        embed.set_footer(text="This post was too long to fit. Full version can be found via the 'View "
                                              "Post' button above")

                    await self.client.send_message(message.channel, embed=embed)

                # Who-is command
                # Assistance from https://gist.github.com/Grewoss/c0601832982a99f59cc73510f7841fe4
                if message.content.upper().startswith(".WHOIS"):
                    print("{0}: {1} requested '.WHOIS'".format(curtime.get_time(), user_name))
                    try:
                        user = message.mentions[0]
                    except IndexError:
                        await self.client.send_message(message.channel, "You `@` a role, not a user!")
                    full_user_name = "{}#{}".format(user.name, user.discriminator)
                    if message.content[7:] is None:
                        await self.client.send_message(message.channel, "You forgot to '@' a user!")
                    else:
                        try:
                            user_join_date = str(user.joined_at).split('.', 1)[0]
                            user_created_at_date = str(user.created_at).split('.', 1)[0]
                            avatar = user.avatar_url if user.avatar else user.default_avatar_url

                            embed = discord.Embed(color=settings.embed_color)
                            embed.set_author(name="User Info")
                            embed.add_field(name="Username:"******"User ID:", value=user.id)
                            embed.add_field(name="Joined the server on:", value=user_join_date[:10])
                            embed.add_field(name="User Created on:", value=user_created_at_date[:10])
                            embed.add_field(name="User Status:", value=str(user.status).title())
                            embed.add_field(name="User Game:", value=user.game)
                            embed.add_field(name="User Custom Name:", value=user.nick)
                            embed.add_field(name="User Role Color:", value=user.color)
                            if len(user.roles) > 1:  # TIL @everyone is a role that is assigned to everyone but hidden
                                embed.add_field(name="User Top Role (Level):", value=user.top_role)
                            else:
                                embed.add_field(name="User Top Role (Level):", value="User has no roles")
                            embed.add_field(name="User Avatar URL", value=avatar)
                            embed.set_thumbnail(url=user.avatar_url)
                            await self.client.send_message(message.channel, embed=embed)
                        except (IndexError, AttributeError):
                            print("{0}: {1} requested '.WHOIS' but they DIDN'T exist".format(curtime.get_time(),
                                                                                             user_name))
                            await self.client.send_message(message.channel, "Sorry, but I couldn't find that user")

                if message.content.upper().startswith(".BANLIST"):
                    ban_list = await self.client.get_bans(message.server)
                    if not ban_list:
                        await self.client.send_message(message.channel, "This server doesn't have anyone banned (yet)")
                    else:
                        userid = [user.id for user in ban_list]
                        name = [user.name for user in ban_list]
                        discriminator = [user.discriminator for user in ban_list]
                        bot = [user.bot for user in ban_list]

                        newlist = []
                        for item in bot:
                            if item:
                                item = "<:bottag:473742770671058964>"
                            else:
                                item = ""
                            newlist.append(item)
                        bot = newlist

                        total = list((zip(userid, name, discriminator, bot)))

                        # Thanks to happypetsy on stackoverflow for helping me with this!
                        pretty_list = set()
                        for details in total:
                            data = "•<@{}>{} ({}#{}) ".format(details[0], details[3], details[1], details[2])
                            pretty_list.add(data)

                        await self.client.send_message(message.channel,
                                                       "**Ban list:** \n{}".format("\n".join(pretty_list)))

                # Create an Invite
                if message.content.upper().startswith(".CREATEINVITE"):
                    invite = await self.client.create_invite(destination=message.channel, max_age=0, temporary=False,
                                                             unique=True)
                    await self.client.send_message(message.channel, invite)

                if message.content.upper().startswith(".INVITE"):
                    if not message.raw_mentions:
                        await self.client.send_message(message.channel, 'You need to `@` a user (maybe you meant '
                                                                        '`.createinvite` :thinking:')
                    else:
                        invite_target = message.raw_mentions[0]
                        user = await self.client.get_user_info(invite_target)
                        invite = await self.client.create_invite(destination=message.channel, max_age=0,
                                                                 temporary=False,
                                                                 unique=True)
                        try:
                            await self.client.send_message(
                                user, "<@{}> ({}) wants to invite  you to `{}`. You can join with this link: {}".format(
                                    message.author.id, message.author.name, message.server.name, invite))
                        except discord.Forbidden:
                            await self.client.send_message(message.channel, "Sorry, but I cannot send a message to "
                                                                            "that user due to there privacy settings "
                                                                            ":(")
                # Roulette system
                if message.content.upper().startswith(".ROULETTE"):
                    if message.content.upper().startswith(".ROULETTE HELP"):
                        print("{0}: {1} requested roulette help")
                        embed = discord.Embed(title="Outcomes:", color=settings.embed_color)
                        embed.set_author(name="Roulette Help")
                        embed.set_thumbnail(url="https://d30y9cdsu7xlg0.cloudfront.net/png/90386-200.png")
                        embed.add_field(name="Zero:", value="0", inline=True)
                        embed.add_field(name="Even:",
                                        value="2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36",
                                        inline=True)
                        embed.add_field(name="Odd:",
                                        value="1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35",
                                        inline=True)
                        embed.add_field(name="How to Play:",
                                        value="Just type '.roulette'",
                                        inline=True)
                        embed.set_footer(
                            text="Maximum bet is 250 karma. Winning on zero will quattuordecuple (x14) your "
                                 "bet while odd and even will double your bet")
                        await self.client.send_message(message.channel, embed=embed)
                        return None
                    if message.content.upper().startswith(".ROULETTE OUTCOMES"):
                        with open('C:/Users/maxla/PycharmProjects/synapsBot remastered/roulette_outcomes.json',
                                  'r') as fp:
                            outcomes = json.load(fp)
                        odd_total = outcomes['odd']
                        even_total = outcomes['even']
                        zero_total = outcomes['zero']
                        total_total = outcomes['total']

                        outcomes_list = [odd_total, even_total, zero_total]
                        total = sum(outcomes_list)
                        embed = discord.Embed(title="\u200b", color=settings.embed_color)
                        embed.set_author(name="Roulette Outcomes 📊")
                        embed.add_field(name="Total number of times 'spun'", value=total, inline=True)
                        embed.add_field(name="Total Bet", value=total_total, inline=False)
                        embed.add_field(name="Odd", value=odd_total, inline=True)
                        embed.add_field(name="Even", value=even_total, inline=True)
                        embed.add_field(name="Zero", value=zero_total, inline=True)
                        await self.client.send_message(message.channel, embed=embed)
                        return None
                    else:
                        await self.client.send_message(
                            message.channel,
                            "How much would you like to bet? It must be between `10` and `250` and cannot be "
                            "more than your karma (`{}`)".format(karma.get_karma(user_id)))
                        bet_amount_message = await self.client.wait_for_message(
                            timeout=120, author=message.author, channel=message.channel)
                        try:
                            bet_amount = int(bet_amount_message.content)
                            print("{0}: Bet {1}".format(curtime.get_time(), bet_amount))
                        except ValueError:
                            await self.client.send_message(
                                message.channel, "Sorry, you need to bet a number between `10` and `250`")
                            return
                        except IndexError:
                            await self.client.send_message(
                                message.channel, "Sorry, you need to bet a number between `10` and `250`")
                            return

                        if 10 <= bet_amount <= 250:
                            if bet_amount > author_karma:
                                await self.client.send_message(
                                    message.channel, "You don't have enough karma! You must bet under `{}`".format(
                                        karma.get_karma(user_id)))
                                return

                            with open('C:/Users/maxla/PycharmProjects/synapsBot remastered/roulette_outcomes.json',
                                      'r') as fp:
                                outcomes = json.load(fp)
                            outcomes['total'] += bet_amount
                            with open('C:/Users/maxla/PycharmProjects/synapsBot remastered/roulette_outcomes.json',
                                      'w') as fp:
                                json.dump(outcomes, fp, sort_keys=True, indent=4)

                            outcomes = ["zero", "even", "odd"]
                            await self.client.send_message(
                                message.channel,
                                "What outcome would you like to bet on? The options are `zero`, `even`, or "
                                "`odd`")
                            outcomes_response = await self.client.wait_for_message(
                                timeout=120, author=message.author, channel=message.channel)

                            try:
                                outcomes_formatted = outcomes_response.content
                                outcomes_formatted = outcomes_formatted.lower()
                                print("{0}: Outcome set to {1}".format(curtime.get_time(), outcomes_formatted))
                            except AttributeError:
                                await self.client.send_message(
                                    message.channel,
                                    "<@{}> DIDN'T respond fast enough, so the roulette was canceled".format(
                                        message.author.id))
                                return

                            if outcomes_formatted in outcomes:
                                print("{0}: Outcome set to {1}".format(curtime.get_time(), outcomes_formatted))
                                karma.user_add_karma(user_id, -int(bet_amount))
                                print("{0}: subtracted {1} karma for bet".format(curtime.get_time(), -int(bet_amount)))
                                rolling_message = await self.client.send_message(message.channel, "Spinning")
                                await asyncio.sleep(.25)
                                await self.client.edit_message(rolling_message, "Spinning.")
                                await asyncio.sleep(.25)
                                await self.client.edit_message(rolling_message, "Spinning..")
                                await asyncio.sleep(.25)
                                await self.client.edit_message(rolling_message, "Spinning...")
                                await asyncio.sleep(.25)
                                await self.client.delete_message(rolling_message)

                                spin = random.randint(0, 36)
                                print("{0}: Landed on {1}".format(curtime.get_time(), spin))
                                msg = await self.client.send_message(message.channel, "It landed on `{}`!".format(spin))
                                if msg.content == "It landed on `0`!":
                                    await self.client.pin_message(msg)
                                    david_dm = await self.client.get_user_info("240608458888445953")
                                    await self.client.send_message(david_dm,
                                                                   "Someone landed on 0 via roulette in `{}`".format(
                                                                       message.server.name))

                                if spin == 0:
                                    with open(
                                            'C:/Users/maxla/PycharmProjects/synapsBot remastered/roulette_outcomes.json',
                                            'r') as fp:
                                        outcomes = json.load(fp)
                                    outcomes['zero'] += 1
                                    with open(
                                            'C:/Users/maxla/PycharmProjects/synapsBot remastered/roulette_outcomes.json',
                                            'w') as fp:
                                        json.dump(outcomes, fp, sort_keys=True, indent=4)

                                    if outcomes_formatted == "zero":
                                        karma.user_add_karma(user_id, int(bet_amount * 14))
                                        msg = await self.client.send_message(
                                            message.channel,
                                            "Winner! :tada:\n You quattuordecuple up on karma for a total of "
                                            "`{}`!".format(karma.get_karma(user_id)))
                                        print("{0}: won on zero! {1}".format(curtime.get_time(), bet_amount))
                                        await self.client.pin_message(msg)
                                        return
                                    else:
                                        await self.client.send_message(
                                            message.channel,
                                            "Sorry, better luck next time. You now have `{}` karma".format(
                                                karma.get_karma(user_id)))
                                else:
                                    if spin % 2 == 0:
                                        with open(
                                                'C:/Users/maxla/PycharmProjects/synapsBot '
                                                'remastered/roulette_outcomes.json',
                                                'r') as fp:
                                            outcomes = json.load(fp)
                                        outcomes['even'] += 1
                                        with open(
                                                'C:/Users/maxla/PycharmProjects/synapsBot '
                                                'remastered/roulette_outcomes.json',
                                                'w') as fp:
                                            json.dump(outcomes, fp, sort_keys=True, indent=4)

                                        if outcomes_formatted == "even":
                                            karma.user_add_karma(user_id, int(bet_amount * 2))
                                            await self.client.send_message(message.channel,
                                                                           "Winner! :tada:\n You doubled up on karma "
                                                                           "for a total of `{}`!".format(
                                                                               karma.get_karma(user_id)))
                                        else:
                                            await self.client.send_message(
                                                message.channel,
                                                "Sorry, better luck next time. You now have `{}` karma".format(
                                                    karma.get_karma(user_id)))
                                    else:
                                        with open(
                                                'C:/Users/maxla/PycharmProjects/synapsBot '
                                                'remastered/roulette_outcomes.json', 'r') as fp:
                                            outcomes = json.load(fp)
                                        outcomes['odd'] += 1
                                        with open(
                                                'C:/Users/maxla/PycharmProjects/synapsBot '
                                                'remastered/roulette_outcomes.json', 'w') as fp:
                                            json.dump(outcomes, fp, sort_keys=True, indent=4)
                                        if outcomes_formatted == "odd":
                                            karma.user_add_karma(user_id, int(bet_amount * 2))
                                            await self.client.send_message(message.channel,
                                                                           "Winner! :tada:\n You doubled up on karma "
                                                                           "for a total of `{}`!".format(
                                                                               karma.get_karma(user_id)))
                                        else:
                                            await self.client.send_message(
                                                message.channel,
                                                "Sorry, better luck next time. You now have `{}` karma".format(
                                                    karma.get_karma(user_id)))
                            else:
                                await self.client.send_message(
                                    message.channel, "`ERROR:` You needed to enter `zero`, `even`, or `odd`")
                        else:
                            await self.client.send_message(message.channel,
                                                           "Sorry, you need to bet a number between `10` and `250`")
                            return

                if message.content.upper().startswith(".BANNEDWORDS"):
                    banned_words = settings.get_json(
                        "C:/Users/maxla/PycharmProjects/synapsBot remastered/banned_words.json")
                    await self.client.send_message(
                        message.channel, "**Banned Words List:** \n• `{}`".format("`\n• `".join(banned_words)))

                if message.content.upper().startswith(".INSULT"):
                    insults = settings.get_json("insults.json")
                    if not message.raw_mentions:
                        await self.client.send_message(message.channel,
                                                       "<@{}>, {}".format(message.author.id, random.choice(insults)))
                    else:
                        mention = message.raw_mentions[0]
                        if mention == self.client.user.id:
                            await self.client.send_message(message.channel,
                                                           "How original. No one else had thought of trying to get "
                                                           "the bot to insult itself. I applaud your creativity. "
                                                           "Yawn. Perhaps this is why you don't have friends. You "
                                                           "don't add anything new to any conversation. You are more "
                                                           "of a bot than me, predictable answers, and absolutely "
                                                           "dull to have an actual conversation with.")
                            return
                        await self.client.send_message(message.channel, "<@{}>, {}".format(message.raw_mentions[0],
                                                                                           random.choice(insults)))

        else:
            return
예제 #8
0
파일: admin.py 프로젝트: StoGFly/synapsBot
    async def on_message(self, message):
        if message.author == self.client.user:
            return

        # Message author variables
        user_id = message.author.id
        user_name = message.author
        server = message.server

        # Banned Words
        banned_words = settings.get_json("banned_words.json")

        if any(word in message.content.upper() for word in banned_words):
            karma.user_add_karma(user_id, -50)
            await self.client.delete_message(message)
            dm_id = await self.client.get_user_info(user_id)
            await self.client.send_message(dm_id, "NO POOPY DOOPY WORDSIES!1! THE HECKIN BOOPIN POOPIN DOOPIN PUPPER "
                                                  "SUPPER LUPPER DOGGO NIGGOS NOT LIEK IT!!! BRB HAVIN A ZOOMIE! "
                                                  "XDDDLOLOELELALAL\nYou can see what is banned via the `.bannedwords` "
                                                  "command.")
            return

        if message.author.server_permissions.administrator:
            if message.content.upper().startswith(".SERVERRULES"):
                await self.client.delete_message(message)
                embed = discord.Embed(title="Synaps Rules and Info",
                                      url="https://steamcommunity.com/groups/team_synaps",
                                      color=settings.embed_color)
                embed.set_thumbnail(url="https://goo.gl/ibJU2z")
                embed.add_field(name="📜 Rules 1.)", value="No spamming.", inline=True)
                embed.add_field(name="👙 Rules 2.)", value="No NSFW in Discussion.", inline=True)
                embed.add_field(name="🎵 Rules 3.)", value="No music requests in any channel but the music channel",
                                inline=True)
                embed.add_field(name="🔰 Getting Verified:",
                                value="Add `[Synaps]` to your steam name and DM a Admin.", inline=True)
                embed.add_field(
                    name="🔸 Getting Member *(How to get access to other channels)*:",
                    value="Read the rules above and type `.accept` in this channel. If for whatever reason it "
                          "doesn't work, contact an {}.".format(settings.admin_role_name), inline=True)
                await self.client.send_message(message.channel, embed=embed)

            if message.content.upper().startswith(".GIVEKARMA"):
                if not message.raw_mentions:  # For if user doesnt send a message that '@'s someone
                    await self.client.send_message(
                        message.channel,
                        "You need to `@` a user and give an amount. Example: `.givekarma @Mehvix#7172 10`")
                else:
                    try:
                        target = message.content.split(" ")
                        target_user = message.raw_mentions[0]
                        target_amount = target[2]
                        karma.user_add_karma(target_user, int(target_amount))
                        await self.client.send_message(message.channel,
                                                       "You gave <@{}> `{}` karma. They now have a total of `{}` "
                                                       "karma".format(target_user, target_amount, karma.get_karma(
                                                           target_user)))
                    except IndexError:
                        await self.client.send_message(
                            message.channel, "You either didn't correctly `@` a user or enter in a amount.")

            if message.content.upper().startswith(".MUTE"):
                role = discord.utils.get(message.server.roles, name=settings.mute_role_name)
                if not message.raw_mentions:
                    await self.client.send_message(message.channel, "You need to `@` a user")
                else:
                    mute_target = message.raw_mentions[0]
                    person = await self.client.get_user_info(mute_target)
                    print("{0}: {1} muted {2}".format(curtime.get_time(), user_name, person.name))
                    await self.client.add_roles(message.mentions[0], role)
                    await self.client.send_message(
                        message.channel, "<@{0}> muted <@{1}>".format(message.author.id, mute_target))

            if message.content.upper().startswith(".UNMUTE"):
                role = discord.utils.get(message.server.roles, name=settings.mute_role_name)
                if not message.raw_mentions:
                    await self.client.send_message(message.channel, "You need to `@` a user")
                else:
                    unmute_target = message.content[10:-1]
                    person = await self.client.get_user_info(message.raw_mentions[0])
                    print("{0}: {1} unmuted {2}".format(curtime.get_time(), user_name, person.name))
                    await self.client.remove_roles(message.mentions[0], role)
                    await self.client.send_message(
                        message.channel, "<@{0}> unmuted <@{1}>".format(message.author.id, unmute_target))

            if message.content.upper().startswith(".BAN "):
                if not message.raw_mentions:
                    await self.client.send_message(message.channel, "You need to `@` a user")
                else:
                    reason = message.content.split(" ")
                    try:
                        reason = reason[2]
                    except IndexError:
                        reason = False
                    print(reason)
                    ban_target = message.raw_mentions[0]
                    print("{0}: {1} banned {2}".format(curtime.get_time(), user_name, ban_target))
                    try:
                        await self.client.ban(member=server.get_member(ban_target))
                    except AttributeError:
                        await self.client.send_message(message.channel, "That user is either not in the server or "
                                                                        "already banned")
                        return
                    await self.client.send_message(message.channel, "<@{}> was banned".format(message.raw_mentions[0]))

            if message.content.upper().startswith(".BANWORD "):
                word = message.content[9:]
                word = word.upper()
                fp = "banned_words.json"
                banned_words = settings.get_json(fp)
                banned_words.insert(0, word)
                with open(fp, 'w') as outfile:
                    json.dump(banned_words, outfile)
                await self.client.send_message(
                    message.channel, "The word / sentence `{}` was banned. The full list of banned words can be"
                                     " found via `.bannedwords`".format(word))

            if message.content.upper().startswith(".KICK"):
                if not message.raw_mentions:
                    await self.client.send_message(message.channel, "You need to `@` a user")
                else:
                    kick_target = message.raw_mentions[0]
                    print("{0}: {1} kicked {2}".format(curtime.get_time(), user_name, kick_target))
                    await self.client.kick(member=server.get_member(kick_target))

            if message.content.upper().startswith(".UNBAN"):
                if not message.raw_mentions:
                    await self.client.send_message(message.channel, "You need to `@` a user")
                else:
                    unban_target = message.raw_mentions[0]
                    print("{0}: {1} unbanned {2}".format(curtime.get_time(), user_name, unban_target))
                    banned = await self.client.get_user_info(unban_target)
                    await self.client.unban(message.server, banned)
                    await self.client.send_message(message.channel,
                                                   "<@{}> was unbanned :tada:".format(unban_target))

            if message.content.upper().startswith(".CLEAR "):
                channel = message.channel
                amount = message.content[7:]
                messages = []
                try:
                    async for message in self.client.logs_from(channel, limit=int(amount) + 1):
                        messages.append(message)
                    await self.client.delete_messages(messages)
                    await self.client.send_message(channel, "<@{}> deleted `{}` messages".format(user_id, amount))
                except discord.HTTPException:
                    await self.client.send_message(
                        channel, "You can only bulk delete messages that are less than 14 days old.")
                except (ValueError, discord.ClientException):
                    await self.client.send_message(channel,
                                                   "You need to give a number between `2` and `99`")

            if message.content.upper().startswith(".NICK "):
                if not message.raw_mentions:
                    await self.client.send_message(message.channel, "You need to `@` a user")
                else:
                    nick_target = message.mentions[0]
                    nick_name = message.content.split(" ")
                    nick_name = nick_name[2:]
                    await self.client.change_nickname(nick_target, " ".join(nick_name))
                    print("{0}: {1} named {2} to {3}".format(curtime.get_time(), user_name, nick_target, " ".join(nick_name)))

                    await self.client.send_message(message.channel, "Set `{}`'s nick to `{}`".format(nick_target, " ".join(nick_name)))

        else:
            return