Ejemplo n.º 1
0
 async def testgetpracticestats(self, ctx, message_ID=None):
     ID = message_ID
     c = self.bot.get_channel('430496334340947978')
     if message_ID is None:
         async for message in self.bot.logs_from(c, limit=1, reverse=True):
             m = await self.bot.get_message(c, message.id)
             pass
     if message_ID is not None:
         m = await self.bot.get_message(c, ID)
         pass
     try:
         x = 0
         ser = ctx.message.server
         s = discord.utils.get(ser.roles, id='432550860229443594')
         acs = discord.utils.get(ser.roles, id='430495770014253056')
         u = ctx.message.author
         if s in u.roles or acs in u.roles:
             await self.bot.say('For which region do you need stats?')
             try:
                 a = await self.bot.wait_for_message(author=u, timeout=15)
                 if a.content.lower().strip() == 'eu':
                     r = await self.bot.get_reaction_users(
                         discord.Reaction(emoji='🇪🇺', message=m))
                     pass
                 if a.content.lower().strip() == 'na':
                     r = await self.bot.get_reaction_users(
                         discord.Reaction(emoji='🇺🇸', message=m))
                     pass
             except Exception:
                 await self.bot.say('Canceling operation.')
             m = await self.bot.say(r[x].name)
             while True:
                 try:
                     x += 1
                     m = await self.bot.edit_message(
                         m, f'{m.content}\n{r[x].name}')
                 except Exception:
                     break
             if len(r) > 1:
                 plural = 's'
                 pass
             if len(r) <= 1:
                 plural = ''
                 pass
             await self.bot.say('**{} user{} have reacted.**'.format(
                 len(r), plural))
         else:
             await self.bot.say(
                 'You are not allowed to use this command, only {} can.'.
                 format(s.name))
     except Exception as e:
         print(e)
Ejemplo n.º 2
0
 async def wait_for_dms(self, event, check, timeout=30):
     try:
         data = (
             await self.cogs["Sharding"].handler(
                 action="wait_for_dms",
                 args={"event": event, "check": check, "timeout": timeout},
                 expected_count=1,
                 _timeout=timeout,
             )
         )[0]
     except IndexError:
         raise asyncio.TimeoutError()
     if event == "message":
         channel_id = int(data["channel_id"])
         channel = (
             self.get_channel(channel_id)
             or self.get_user(int(data["author"]["id"])).dm_channel
         )
         return discord.Message(state=self._connection, channel=channel, data=data)
     elif event == "reaction_add":
         emoji = discord.PartialEmoji(
             name=data["emoji"]["name"],
             id=int(id_) if (id_ := data["emoji"]["id"]) else id_,
             animated=data["emoji"]["animated"],
         )
         message = discord.utils.get(
             self._connection._messages, id=int(data["message_id"])
         )
         reaction = discord.Reaction(
             message=message, emoji=emoji, data={"me": False}
         )
         return reaction, await self.get_user_global(int(data["user_id"]))
Ejemplo n.º 3
0
    async def lottery(self, ctx, item, time):
        """
        Создать лотерею
        =lottery <item_name> <>
        Example: =lottery <Бутерброд> <30h, 30m, 30s>
        """
        time_str = int(re.findall('\\d+', time)[0])
        if "h" in time:
            t = time_str * 60 * 24

        elif "m" in time:
            t = time_str * 60
        else:
            t = time_str

        s_time = f'{time}'
        em = discord.Embed(colour=int('0x36393f', 0))
        em.set_author(name=f'🎉 Розыгрыш: {item}')

        msg = await ctx.send(embed=em)
        await msg.add_reaction('🎉')
        await asyncio.sleep(t)

        reaction = discord.Reaction(message=msg, data=ctx, emoji='🎉')
        users = await reaction.users().flatten()
        winner = random.choice(users)
        print(users)
        print(winner)
        await msg.edit(embed=em)
Ejemplo n.º 4
0
 def __init__(self, number, user) -> None:
     self.finished = False
     self.number = number
     self.user = user
     self.count = 0
     self.lock = discord.Reaction(message=None,
                                  data={
                                      "count": 1,
                                      "me": None
                                  },
                                  emoji=str("🔒"))
     self.stop = discord.Reaction(message=None,
                                  data={
                                      "count": 1,
                                      "me": None
                                  },
                                  emoji=str("🛑"))
     self.bulk = []
Ejemplo n.º 5
0
async def close(author, message, open_poll):
    react1 = discord.Emoji()
    react1 = discord.Reaction()
    if (open_poll == None):
        await client.send_message(message.channel,
                                  "There is no poll to close.")
    else:
        reaction_nums = []
        reaction_nums.append(len(open_poll.get_reaction_users(react1)))
Ejemplo n.º 6
0
async def _decode_raw_reaction(bot, payload: discord.RawReactionActionEvent):
    # Fetch all the information
    guild = bot.get_guild(payload.guild_id)
    channel = bot.get_channel(payload.channel_id)
    message = await channel.fetch_message(payload.message_id)
    member = guild.get_member(payload.user_id)

    # Construct reaction
    reaction = discord.Reaction(message=message,
                                data={'me': member == guild.me},
                                emoji=payload.emoji)

    return reaction, member
Ejemplo n.º 7
0
 async def vote(self, ctx):
     msg = await self.bot.say(
         "Should I?\n1. Wear my uniform.\n2. Get breakfast.\n3. Call Natsuki."
     )
     await self.bot.add_reaction(emoji="🛑", message=msg)
     await self.bot.add_reaction(emoji="1\u20e3", message=msg)
     await self.bot.add_reaction(emoji="2\u20e3", message=msg)
     await self.bot.add_reaction(emoji="3\u20e3", message=msg)
     await self.bot.wait_for_reaction(message=msg, emoji="🛑")
     em = discord.Embed(color=0xea7938)
     waa = discord.Reaction(emoji="1\u20e3", message=msg)
     wa = await self.bot.get_reaction_users(waa)
     em.add_field(name='1', value=str(len(wa) - 1))
     wbb = discord.Reaction(emoji="2\u20e3", message=msg)
     wb = await self.bot.get_reaction_users(wbb)
     em.add_field(name='2', value=str(len(wb) - 1))
     wcc = discord.Reaction(emoji="3\u20e3", message=msg)
     wc = await self.bot.get_reaction_users(wcc)
     em.add_field(name='3', value=str(len(wc) - 1))
     em.set_footer(
         text=
         'Do not choose more than one option, just as you would with a normal vote.'
     )
     await self.bot.say(embed=em)
Ejemplo n.º 8
0
 async def giveaway(self, ctx, message_id, channel_id, emoji:discord.Emoji, winners):
     try:
         m = await self.bot.get_message(self.bot.get_channel(channel_id), message_id)
         isla = await self.bot.get_user_info('199436790581559296')
         em = discord.Embed()
         col = str('7E28CC')
         em.color = int('0x' + col, 16)
         em.title = 'Winner of 1 free month of Nitro:'
         wm = await self.bot.send_message(self.bot.get_channel(channel_id), embed = em)
         r = await self.bot.get_reaction_users(discord.Reaction(emoji = emoji, message = m))
         for x in range(0, winners):
             win1 = random.choice(r)
             em.add_field(name = 'ㅤㅤ', value = win1.mention + ' (' + win1.id + ')', inline = True)
             await self.bot.send_message(isla, win1.id)
             await self.bot.edit_message(wm, embed = em)
             r.remove(win1)
     except Exception as e:
         await self.bot.say(e)
Ejemplo n.º 9
0
 async def getpracticestats(self, ctx, message_ID=None):
     ID = message_ID
     c = self.bot.get_channel('430496334340947978')
     if message_ID is None:
         async for message in self.bot.logs_from(c, limit=1, reverse=True):
             m = await self.bot.get_message(c, message.id)
             pass
     if message_ID is not None:
         m = await self.bot.get_message(c, ID)
         pass
     try:
         r = await self.bot.get_reaction_users(
             discord.Reaction(emoji='✅', message=m))
         x = 0
         ser = ctx.message.server
         s = discord.utils.get(ser.roles, id='432550860229443594')
         acs = discord.utils.get(ser.roles, id='430495770014253056')
         u = ctx.message.author
         if s in u.roles or acs in u.roles:
             m = await self.bot.say(r[x].name)
             while True:
                 try:
                     x += 1
                     m = await self.bot.edit_message(
                         m, f'{m.content}\n{r[x].name}')
                 except Exception:
                     break
             if len(r) > 1:
                 plural = 's'
                 pass
             if len(r) <= 1:
                 plural = ''
                 pass
             await self.bot.say('**{} user{} have reacted.**'.format(
                 len(r), plural))
         else:
             await self.bot.say(
                 'You are not allowed to use this command, only {} can.'.
                 format(s.name))
     except Exception as e:
         await self.bot.say(e)
         print(e)
Ejemplo n.º 10
0
 async def process_raw_reaction_event(self, payload: discord.RawReactionActionEvent, add):
     data = {'count': 1, 'me': payload.user_id == self.bot.user.id,
             'emoji': {'id': payload.emoji.id, 'name': payload.emoji.name}
             }
     if data['me']:
         return
     channel: discord.ChannelType = self.bot.get_channel(payload.channel_id)
     message: discord.Message = await channel.fetch_message(payload.message_id)
     reaction: discord.Reaction = discord.Reaction(message=message, data=data)
     guild = await self.bot.fetch_guild(payload.guild_id)
     user = await guild.fetch_member(payload.user_id)
     if self.pollmanager.is_sent_message(payload.message_id):
         poll = self.pollmanager.get_poll_by_msg_id(payload.message_id)
         if not poll.updated_since_start:
             await poll.full_update(reactions=message.reactions, bot_user_id=self.bot.user.id)
         else:
             poll.process_reaction(reaction, user, add=add)
         msg, embed = poll.to_discord()
         self.pollmanager.update_poll(poll)
         await message.edit(content=msg, embed=embed)
Ejemplo n.º 11
0
    async def get_reaction_class(self, message, emoji):
        """
        Adapt raw socket data data to Discord.py Reaction class
        :param message: discord.Message object
        :param emoji: discord.Emoji object
        :return discord.Reaction object
        """
        print('entered ' + sys._getframe().f_code.co_name)

        async def get_msg_reaction_count():
            pass  # TODO: accurately represent the reaction count

        try:
            reaction_obj = discord.Reaction(
                message=message,
                emoji=emoji,
                data={"count": 1, "me": False}
            )
            return reaction_obj

        except:
            traceback.print_exc()
            return None
Ejemplo n.º 12
0
partial_emoji_instance = discord.PartialEmoji(animated=False, name='guido')


class MockPartialEmoji(CustomMockMixin, unittest.mock.MagicMock):
    """
    A MagicMock subclass to mock PartialEmoji objects.

    Instances of this class will follow the specifications of `discord.PartialEmoji` instances. For
    more information, see the `MockGuild` docstring.
    """
    spec_set = partial_emoji_instance


reaction_instance = discord.Reaction(message=MockMessage(),
                                     data={'me': True},
                                     emoji=MockEmoji())


class MockReaction(CustomMockMixin, unittest.mock.MagicMock):
    """
    A MagicMock subclass to mock Reaction objects.

    Instances of this class will follow the specifications of `discord.Reaction` instances. For
    more information, see the `MockGuild` docstring.
    """
    spec_set = reaction_instance

    def __init__(self, **kwargs) -> None:
        _users = kwargs.pop("users", [])
        super().__init__(**kwargs)
Ejemplo n.º 13
0
import discord
import psycopg2
from discord.ext import commands
from googletrans import Translator
from PyDictionary import PyDictionary

import config

from opus_loader import load_opus_lib

load_opus_lib()

bot = commands.Bot(command_prefix=">os.")
cogs_dir = "cogs"

uk = discord.Reaction(emoji="\U0001f1ec\U0001f1e7")
us = discord.Reaction(emoji="\U0001f1fa\U0001f1f8")
jp = discord.Reaction(emoji="\U0001f1ef\U0001f1f5")
ind = discord.Reaction(emoji="\U0001f1ee\U0001f1f3")
es = discord.Reaction(emoji="\U0001f1ea\U0001f1f8")
de = discord.Reaction(emoji="\U0001f1ea\U0001f1f8")
fr = discord.Reaction(emoji="\U0001f1eb\U0001f1f7")
pt = discord.Reaction(emoji="\U0001f1f5\U0001f1f9")
cn = discord.Reaction(emoji="\U0001f1e8\U0001f1f3")
pole = discord.Reaction(emoji="\U0001f1f5\U0001f1f1")

initial_extensions = (
    'cogs.literature',
    'cogs.moderation',
    'cogs.voting',
    'cogs.serverinfo',
    async def start(self, ctx):
        msg = await self.bot.send_message(ctx.message.channel, "What is the episode name?")
        await asyncio.sleep(1)
        epname = await self.bot.wait_for_message(channel=ctx.message.channel)
        epname = epname.content
        try:
            db = psycopg2.connect(host=config.host,database=config.database, user=config.user, password=config.password)
            c = db.cursor()
            c.execute('SELECT * FROM '+epname) 
            table = c.fetchall()
            server = ctx.message.server
            channel = server.get_channel(str(table[0][1]))
            for x in range(0,len(table)):
                await self.bot.wait_for_message(channel=channel, content=table[x][2])
                typer = table[x][3]
                if typer == "n":
                    await self.bot.send_message(channel, table[x][4])
                    print(table[x][4])
                elif typer == "sq":
                    await self.bot.send_message(channel, table[x][4])
                    print(table[x][4])
                    await self.bot.wait_for_message(channel=channel, content=table[x][5])
                    await self.bot.send_message(channel, "Correct!")
                elif typer == "ynv":
                    msg = await self.bot.send_message(channel, table[x][4])
                    await self.bot.add_reaction(emoji="\U00002705", message=msg)
                    await self.bot.add_reaction(emoji="\U0000274e", message=msg)
                    await self.bot.wait_for_reaction(message=msg, emoji="🛑")
                    em = discord.Embed(color=0xea7938)
                    waa = discord.Reaction(emoji="\U00002705", message=msg)
                    wa = await self.bot.get_reaction_users(waa)
                    em.add_field(name='Yes', value=str(len(wa)-1))
                    wbb = discord.Reaction(emoji="\U0000274e", message=msg)
                    wb = await self.bot.get_reaction_users(wbb)
                    em.add_field(name='No', value=str(len(wb)-1))
                    await self.bot.say(embed=em)
                    if len(wa)-1 > len(wb)-1:
                        await self.bot.say("Yes output(still in the works)")
                    elif len(wa)-1 < len(wb)-1:
                        await self.bot.say("No output(still in the works)")
                    if len(wa)-1 == len(wb)-1:
                        await self.bot.say("Tie!(still in the works)")
                elif typer == "nv":
                    msg = await self.bot.send_message(channel, table[x][4])
                    await self.bot.add_reaction(emoji="1\u20e3", message=msg)
                    await self.bot.add_reaction(emoji="2\u20e3", message=msg)
                    await self.bot.add_reaction(emoji="3\u20e3", message=msg)
                    await self.bot.add_reaction(emoji="4\u20e3", message=msg)
                    await self.bot.add_reaction(emoji="5\u20e3", message=msg)
                    await self.bot.add_reaction(emoji="6\u20e3", message=msg)
                    await self.bot.add_reaction(emoji="7\u20e3", message=msg)
                    await self.bot.add_reaction(emoji="8\u20e3", message=msg)
                    await self.bot.add_reaction(emoji="9\u20e3", message=msg)
                    await self.bot.add_reaction(emoji="\U0001f51f", message=msg)
                    await self.bot.wait_for_reaction(message=msg, emoji="🛑")
                    em = discord.Embed(color=0xea7938)
                    waa = discord.Reaction(emoji="1\u20e3", message=msg)
                    one = await self.bot.get_reaction_users(waa)
                    wbb = discord.Reaction(emoji="2\u20e3", message=msg)
                    two = await self.bot.get_reaction_users(wbb)
                    wbb = discord.Reaction(emoji="3\u20e3", message=msg)
                    three = await self.bot.get_reaction_users(wbb)
                    wbb = discord.Reaction(emoji="4\u20e3", message=msg)
                    four = await self.bot.get_reaction_users(wbb)
                    wbb = discord.Reaction(emoji="5\u20e3", message=msg)
                    five = await self.bot.get_reaction_users(wbb)
                    wbb = discord.Reaction(emoji="6\u20e3", message=msg)
                    six = await self.bot.get_reaction_users(wbb)
                    wbb = discord.Reaction(emoji="7\u20e3", message=msg)
                    seven = await self.bot.get_reaction_users(wbb)
                    wbb = discord.Reaction(emoji="8\u20e3", message=msg)
                    eight = await self.bot.get_reaction_users(wbb)
                    wbb = discord.Reaction(emoji="9\u20e3", message=msg)
                    nine = await self.bot.get_reaction_users(wbb)
                    wbb = discord.Reaction(emoji="\U0001f51f", message=msg)
                    ten = await self.bot.get_reaction_users(wbb)
                    nums = []
                    nums.append(int(len(one)))
                    nums.append(int(len(two)))
                    nums.append(int(len(three)))
                    nums.append(int(len(four)))
                    nums.append(int(len(five)))
                    nums.append(int(len(six)))
                    nums.append(int(len(seven)))
                    nums.append(int(len(eight)))
                    nums.append(int(len(nine)))
                    nums.append(int(len(ten)))
                    maxi = nums.index(max(nums)) + 1
                    if maxi == 1:
                        await self.bot.send_message(channel, "1")
                    if maxi == 2:
                        await self.bot.send_message(channel, "2")
                    if maxi == 3:
                        await self.bot.send_message(channel, "3")
                    if maxi == 4:
                        await self.bot.send_message(channel, "4")
                    if maxi == 5:
                        await self.bot.send_message(channel, "5")
                    if maxi == 6:
                        await self.bot.send_message(channel, "6")
                    if maxi == 7:
                        await self.bot.send_message(channel, "7")
                    if maxi == 8:
                        await self.bot.send_message(channel, "8")
                    if maxi == 9:
                        await self.bot.send_message(channel, "9")
                    if maxi == 10:
                        await self.bot.send_message(channel, "10")
                elif typer == "rsq":
                    t = table[x][5]
                    ta = t.split(" ")
                    ppl = await self.bot.send_message(channel, table[x][4])
                    print(ta)
                    for y in range(0,len(ta)):
                        emoji = ta[y]
                        print(emoji)
                        if emoji == "1⃣":
                            emoji = "1\u20e3"
                        if emoji == "2⃣":
                            emoji = "2\u20e3"
                        if emoji == "3⃣":
                            emoji = "3\u20e3"
                        if emoji == "4⃣":
                            emoji = "4\u20e3"
                        if emoji == "5⃣":
                            emoji = "5\u20e3"
                        if emoji == "6⃣":
                            emoji = "6\u20e3"
                        if emoji == "7⃣":
                            emoji = "7\u20e3"
                        if emoji == "8⃣":
                            emoji = "8\u20e3"
                        if emoji == "9⃣":
                            emoji = "9\u20e3"
                        if emoji == "🔟":
                            emoji = "\U0001f51f"
                        await self.bot.wait_for_reaction(message=ppl, emoji=str(emoji))
                    await self.bot.send_message(channel, table[x][6])

                db.close()
        except:
            self.bot.say("It seems that was not a valid episode name. Use >os.epdesign list to find out the list of episodes designed.")
Ejemplo n.º 15
0
    async def on_raw_reaction_add(self, payload):
        def check(m):
            if m.author == user and m.channel == user.dm_channel:
                if m.content.lower() == 'yes':
                    return True
                elif m.content.lower() == 'no':
                    raise SaidNoError
                else:
                    return False
            else:
                return False

        if payload.user_id != self.bot.user.id:
            channel = self.bot.get_guild(config['server_ID']).get_channel(
                payload.channel_id)
            guild = self.bot.get_guild(config['server_ID'])
            user = guild.get_member(payload.user_id)
            message = await channel.fetch_message(payload.message_id)
            emoji = str(payload.emoji)
            reactpayload: ReactionPayload = {
                'count': 0,
                'me': False,
                'emoji': str(payload.emoji)
            }
            reaction = discord.Reaction(message=message,
                                        data=reactpayload,
                                        emoji=str(payload.emoji))
            if message.channel.id == config['shop_Channel']:
                if reaction.emoji in reactions:
                    embed = message.embeds[0]
                    if embed.title == "Tier 1 Roles":
                        print("t1")
                        creditsSelect = f"SELECT Credits FROM Credits WHERE User ={user.id}"
                        credits = await DB.select_one(creditsSelect, DBConn)
                        if credits is not None:
                            if credits[0] >= 5000:
                                count = 0
                                for role in shopRoles['Tier1']:
                                    if count == reactions.index(
                                            reaction.emoji):
                                        roleObj = guild.get_role(role)
                                        roleSelect = f"SELECT count(*) FROM OwnedRoles WHERE User={user.id} AND Role = {roleObj.id}"
                                        roleResult = await DB.select_one(
                                            roleSelect, DBConn)
                                        if roleResult[0] == 0:
                                            if roleObj.id == 555586664827715584:
                                                levelSelect = f"SELECT Level FROM Levels WHERE User ={user.id}"
                                                levelsResult = await DB.select_one(
                                                    levelSelect, DBConn)
                                                if levelsResult[0] >= shopRoles[
                                                        'Tier1'][role]['level']:
                                                    await user.send(
                                                        "Would you like to purchase `Toe Tag` for `5000 credits`?"
                                                    )
                                                    try:
                                                        await self.bot.wait_for(
                                                            'message',
                                                            check=check,
                                                            timeout=30)
                                                        purchaseInsert = f"INSERT INTO OwnedRoles (PurchaseDate, Role, User) VALUES ({int(time.time())},{roleObj.id},{user.id})"
                                                        creditsUpdate = f"UPDATE Credits SET Credits = Credits - 5000 WHERE User = {user.id}"
                                                        await DB.execute(
                                                            creditsUpdate,
                                                            DBConn)
                                                        await DB.execute(
                                                            purchaseInsert,
                                                            DBConn)
                                                        await user.add_roles(
                                                            roleObj)
                                                        await user.send(
                                                            "You have purchased the `Toe Tag` role."
                                                        )
                                                    except SaidNoError:
                                                        await user.send(
                                                            "Role Purchase cancelled!"
                                                        )
                                                    except asyncio.TimeoutError:
                                                        await user.send(
                                                            "Timeout reached. Role Purchase cancelled!"
                                                        )
                                                else:
                                                    msg = await message.channel.send(
                                                        f"{user.mention} Your level is not high enough to purchase this role!"
                                                    )
                                                    await asyncio.sleep(5)
                                                    await msg.delete()
                                            else:
                                                await user.send(
                                                    f"Would you like to buy the `{roleObj.name}` role for `5000 credits`?"
                                                )
                                                try:
                                                    await self.bot.wait_for(
                                                        'message',
                                                        check=check,
                                                        timeout=30)
                                                    purchaseInsert = f"INSERT INTO OwnedRoles (PurchaseDate, Role, User) VALUES ({int(time.time())},{roleObj.id},{user.id})"
                                                    creditsUpdate = f"UPDATE Credits SET Credits = Credits - 5000 WHERE User = {user.id}"
                                                    await DB.execute(
                                                        creditsUpdate, DBConn)
                                                    await DB.execute(
                                                        purchaseInsert, DBConn)
                                                    await user.send(
                                                        f"You have purchased the `{roleObj.name}` role. Please use `!chooserole` in <#555581400414289935> to activate it"
                                                    )
                                                except SaidNoError:
                                                    await user.send(
                                                        "Role Purchase cancelled!"
                                                    )
                                                except asyncio.TimeoutError:
                                                    await user.send(
                                                        "Timeout reached. Role Purchase cancelled!"
                                                    )
                                        else:
                                            if roleObj.id != 555586664827715584:
                                                msg = await message.channel.send(
                                                    f"{user.mention} You already have this role! Please use `!chooserole` in <#555581400414289935> to activate it"
                                                )
                                            else:
                                                msg = await message.channel.send(
                                                    f"{user.mention} You already have this role!"
                                                )
                                            await asyncio.sleep(5)
                                            await msg.delete()
                                    count += 1
                            else:
                                msg = await message.channel.send(
                                    f"{user.mention} You do not have enough credits to purchase this role!"
                                )
                                await asyncio.sleep(5)
                                await msg.delete()
                    elif embed.title == "Tier 2 Roles":
                        creditsSelect = f"SELECT Credits FROM Credits WHERE User ={user.id}"
                        credits = await DB.select_one(creditsSelect, DBConn)
                        if credits is not None:
                            if credits[0] >= 3000:
                                count = 0
                                for role in shopRoles['Tier2']:
                                    if count == reactions.index(
                                            reaction.emoji):
                                        roleObj = guild.get_role(role)
                                        roleSelect = f"SELECT count(*) FROM OwnedRoles WHERE User={user.id} AND Role = {roleObj.id}"
                                        roleResult = await DB.select_one(
                                            roleSelect, DBConn)
                                        if roleResult[0] == 0:
                                            await user.send(
                                                f"Would you like to buy the `{roleObj.name}` role for `3000 credits`?"
                                            )
                                            try:
                                                await self.bot.wait_for(
                                                    'message',
                                                    check=check,
                                                    timeout=30)
                                                purchaseInsert = f"INSERT INTO OwnedRoles (PurchaseDate, Role, User) VALUES ({int(time.time())},{roleObj.id},{user.id})"
                                                creditsUpdate = f"UPDATE Credits SET Credits = Credits - 3000 WHERE User = {user.id}"
                                                await DB.execute(
                                                    creditsUpdate, DBConn)
                                                await DB.execute(
                                                    purchaseInsert, DBConn)
                                                await user.send(
                                                    f"You have purchased the `{roleObj.name}` role. Please use `!chooserole` in <#555581400414289935> to activate it"
                                                )
                                            except SaidNoError:
                                                await user.send(
                                                    "Role Purchase cancelled!")
                                            except asyncio.TimeoutError:
                                                await user.send(
                                                    "Timeout reached. Role Purchase cancelled!"
                                                )
                                        else:
                                            msg = await message.channel.send(
                                                f"{user.mention} You already have this role! Please use `!chooserole` in <#555581400414289935> to activate it"
                                            )
                                            await asyncio.sleep(5)
                                            await msg.delete()
                                    count += 1
                            else:
                                msg = await message.channel.send(
                                    f"{user.mention} You do not have enough credits to purchase this role!"
                                )
                                await asyncio.sleep(5)
                                await msg.delete()
                    elif embed.title == "Tier 3 Roles":
                        creditsSelect = f"SELECT Credits FROM Credits WHERE User ={user.id}"
                        credits = await DB.select_one(creditsSelect, DBConn)
                        if credits is not None:
                            if credits[0] >= 1000:
                                count = 0
                                for role in shopRoles['Tier3']:
                                    if count == reactions.index(
                                            reaction.emoji):
                                        roleObj = guild.get_role(role)
                                        roleSelect = f"SELECT count(*) FROM OwnedRoles WHERE User={user.id} AND Role = {roleObj.id}"
                                        roleResult = await DB.select_one(
                                            roleSelect, DBConn)
                                        if roleResult[0] == 0:
                                            await user.send(
                                                f"Would you like to buy the `{roleObj.name}` role for `1000 credits`?"
                                            )
                                            try:
                                                await self.bot.wait_for(
                                                    'message',
                                                    check=check,
                                                    timeout=30)
                                                purchaseInsert = f"INSERT INTO OwnedRoles (PurchaseDate, Role, User) VALUES ({int(time.time())},{roleObj.id},{user.id})"
                                                creditsUpdate = f"UPDATE Credits SET Credits = Credits - 1000 WHERE User = {user.id}"
                                                await DB.execute(
                                                    creditsUpdate, DBConn)
                                                await DB.execute(
                                                    purchaseInsert, DBConn)
                                                await user.send(
                                                    f"You have purchased the `{roleObj.name}` role. Please use `!chooserole` in <#555581400414289935> to activate it"
                                                )
                                            except SaidNoError:
                                                await user.send(
                                                    "Role Purchase cancelled!")
                                            except asyncio.TimeoutError:
                                                await user.send(
                                                    "Timeout reached. Role Purchase cancelled!"
                                                )
                                        else:
                                            msg = await message.channel.send(
                                                f"{user.mention} You already have this role! Please use `!chooserole` in <#555581400414289935> to activate it"
                                            )
                                            await asyncio.sleep(5)
                                            await msg.delete()
                                    count += 1
                            else:
                                msg = await message.channel.send(
                                    f"{user.mention} You do not have enough credits to purchase this role!"
                                )
                                await asyncio.sleep(5)
                                await msg.delete()
                await reaction.message.remove_reaction(reaction.emoji, user)
Ejemplo n.º 16
0
            await invite(author, message)
        elif (message.content.startswith("=git")):
            await git(author, message)
        elif (message.content.startswith("=poll")):
            open_poll = await poll(author, message, open_poll)
        elif (message.content.startswith("=close")):
            await close(author, message, open_poll)
        else:
            await client.send_message(
                message.channel,
                "Command \"" + message.content + "\" not recognized.")
    message_array = message.content.lower().split(" ")
    for i in message_array:
        for j in change:
            if i == j:
                await client.send_message(
                    message.channel,
                    change[j].format(person=message.author.name))


@client.event
async def on_ready():
    print("Logged in as {user}".format(user=client.user))
    await client.change_presence(game=help_game)


#run the client
client.run(token)
react1 = discord.Emoji()
react1 = discord.Reaction()