コード例 #1
0
    async def count(self, ctx, *, name):
        """Shows howmany times an idol has been called. [Format: %count (idol's name)]"""
        try:
            c.execute(
                "SELECT ID, FullName, StageName, Aliases FROM groupmembers.Member"
            )
            all_members = fetch_all()
            final_count = "Unknown"
            for mem in all_members:
                check = 0
                ID = mem[0]
                full_name = mem[1]
                stage_name = mem[2]
                aliases = mem[3]
                if aliases != "NULL":
                    aliases = aliases.split(',')
                    for alias in aliases:
                        if alias.lower() == name.lower():
                            check = 1
                if name.lower() == full_name.lower() or name.lower(
                ) == stage_name.lower():
                    check = 1
                if check == 1:
                    c.execute(
                        "SELECT COUNT(*) FROM groupmembers.Count WHERE MemberID = %s",
                        (ID, ))
                    counter = fetch_one()
                    if counter == 0:
                        await ctx.send(
                            f"> **{full_name} ({stage_name}) has not been called by a user yet.**"
                        )
                    else:
                        c.execute(
                            "SELECT Count FROM groupmembers.Count WHERE MemberID = %s",
                            (ID, ))
                        counter = fetch_one()
                        c.execute(
                            "SELECT MemberID FROM groupmembers.Count ORDER BY Count DESC"
                        )
                        all_counters = fetch_all()
                        count = 0
                        for rank in all_counters:
                            count += 1
                            mem_id = rank[0]
                            if mem_id == ID:
                                final_count = count

                        await ctx.send(
                            f"> **{full_name} ({stage_name}) has been called {counter} times at rank {final_count}.**"
                        )
        except Exception as e:
            log.console(e)
コード例 #2
0
 async def leaderboard(self, ctx):
     """Shows Top 10 Users [Format: %leaderboard][Aliases: leaderboards, lb]"""
     c.execute("SELECT count(UserID) FROM currency.Currency")
     counter = fetch_one()
     embed = discord.Embed(title=f"Currency Leaderboard", color=0xffb6c1)
     embed.set_author(name="Irene", url='https://www.youtube.com/watch?v=dQw4w9WgXcQ', icon_url='https://cdn.discordapp.com/emojis/693392862611767336.gif?v=1')
     embed.set_footer(text="Type %bal (user) to view their balance.", icon_url='https://cdn.discordapp.com/emojis/683932986818822174.gif?v=1')
     if counter == 0:
         await ctx.send("> **There are no users to display.**", delete_after=60)
     if counter > 0:
         c.execute("Select UserID,Money FROM currency.Currency")
         amount = fetch_all()
         sort_money = []
         for sort in amount:
             new_user = [sort[0], int(sort[1])]
             sort_money.append(new_user)
         sort_money.sort(key=lambda x: x[1], reverse=True)
         count = 0
         for a in sort_money:
             count += 1
             UserID = a[0]
             Money = a[1]
             UserName = self.client.get_user(UserID)
             if count <= 10:
                 embed.add_field(name=f"{count}) {UserName} ({UserID})", value=await shorten_balance(str(Money)), inline=True)
         await ctx.send(embed=embed)
コード例 #3
0
    async def movelinks(self, ctx):
        """Add DC LINKS to main link table."""
        c.execute("SELECT link, member FROM currency.dchdlinks")
        hd_links = fetch_all()
        count = 0
        for link in hd_links:
            url = link[0]
            member_name = link[1]
            member_id = None
            if member_name == "Gahyeon":
                member_id = 163
            elif member_name == "Siyeon":
                member_id = 159
            elif member_name == "Yoohyeon":
                member_id = 161
            elif member_name == "JIU":
                member_id = 157
            elif member_name == "SUA":
                member_id = 158
            elif member_name == "Dami":
                member_id = 162
            elif member_name == "Handong":
                member_id = 160
            else:
                pass

            try:
                c.execute("INSERT INTO groupmembers.imagelinks VALUES (%s,%s)", (url, member_id))
                DBconn.commit()
                count += 1
            except Exception as e:
                log.console(e)
                pass
        await ctx.send(f"> **Added {count} links.**")
コード例 #4
0
 async def countleaderboard(self, ctx):
     """Shows leaderboards for how many times an idol has been called. [Format: %clb]"""
     embed = discord.Embed(title=f"Idol Leaderboard", color=0xffb6c1)
     embed.set_author(
         name="Irene",
         url='https://www.youtube.com/watch?v=dQw4w9WgXcQ',
         icon_url=
         'https://cdn.discordapp.com/emojis/693392862611767336.gif?v=1')
     embed.set_footer(
         text="Type %count (idol name) to view their individual stats.",
         icon_url=
         'https://cdn.discordapp.com/emojis/683932986818822174.gif?v=1')
     c.execute(
         "SELECT MemberID, Count FROM groupmembers.Count ORDER BY Count DESC"
     )
     all_members = fetch_all()
     count_loop = 0
     for mem in all_members:
         count_loop += 1
         if count_loop <= 10:
             MemberID = mem[0]
             count = mem[1]
             c.execute(
                 "SELECT fullname, stagename FROM groupmembers.Member WHERE ID = %s",
                 (MemberID, ))
             idol = c.fetchone()
             embed.add_field(name=f"{count_loop}) {idol[0]} ({idol[1]})",
                             value=count)
     await ctx.send(embed=embed)
コード例 #5
0
 async def new_task5(self):
     check = True
     try:
         c.execute("SELECT link FROM currency.links")
         links = fetch_all()
     except Exception as e:
         check = False
         pass
     if check:
         try:
             for link in links:
                 c.execute(
                     "SELECT LinkID FROM currency.links WHERE Link = %s",
                     link)
                 link_id = fetch_one()
                 async with aiohttp.ClientSession() as session:
                     async with session.get('{}'.format(link[0])) as r:
                         if r.status == 200:
                             page_html = await r.text()
                             # log.console(page_html)
                             page_soup = soup(page_html, "html.parser")
                             view_count = (page_soup.find(
                                 "div", {"class": "watch-view-count"})).text
                             now = datetime.now()
                             c.execute(
                                 "INSERT INTO currency.ViewCount VALUES (%s,%s,%s)",
                                 (link_id, view_count, now))
                             self.view_count.append(view_count)
                             self.now.append(now)
                             DBconn.commit()
             # log.console("Updated Video Views Tracker")
         except Exception as e:
             log.console(e)
     self.view_count = []
     self.now = []
コード例 #6
0
 async def scandrive(self, ctx, name="NULL", member_id=0):
     """Scan DriveIDs Table and update other tables."""
     try:
         c.execute("SELECT id, linkid, name FROM archive.DriveIDs")
         all_links = fetch_all()
         for pic in all_links:
             try:
                 ID = pic[0]
                 Link_ID = pic[1]
                 Link_Name = pic[2]
                 new_link = f"https://drive.google.com/uc?export=view&id={Link_ID}"
                 c.execute("SELECT Name FROM archive.ChannelList")
                 all_names = fetch_all()
                 if name == "NULL" and member_id == 0:
                     for idol_name in all_names:
                         idol_name = idol_name[0]
                         if idol_name == Link_Name and (
                                 idol_name != "Group"
                                 or idol_name != "MDG Group"):
                             c.execute(
                                 "SELECT ID FROM groupmembers.Member WHERE StageName = %s",
                                 (idol_name, ))
                             member_id1 = fetch_one()
                             c.execute(
                                 "INSERT INTO groupmembers.ImageLinks VALUES(%s,%s)",
                                 (new_link, member_id1))
                             c.execute(
                                 "DELETE FROM archive.DriveIDs WHERE ID = %s",
                                 (ID, ))
                             DBconn.commit()
                 elif Link_Name.lower() == name.lower():
                     c.execute("DELETE FROM archive.DriveIDs WHERE ID = %s",
                               (ID, ))
                     c.execute(
                         "INSERT INTO groupmembers.ImageLinks VALUES(%s,%s)",
                         (new_link, member_id))
                     DBconn.commit()
             except Exception as e:
                 log.console(e)
                 DBconn.commit()
         await ctx.send(f"> **Completed Scan**")
     except Exception as e:
         log.console(e)
         DBconn.commit()
コード例 #7
0
 async def deletephotos(self):
     c.execute("SELECT FileName from archive.ArchivedChannels")
     allfiles = fetch_all()
     file_list = []
     for file in allfiles:
         file_list.append(file[0])
     all_photos = os.listdir('Photos')
     for photo in all_photos:
         if photo != "placeholder.txt" and photo not in file_list:
             try:
                 os.unlink('Photos/{}'.format(photo))
             except Exception as e:
                 pass
コード例 #8
0
 def checker():
     c.execute("SELECT COUNT(*) FROM archive.ArchivedChannels")
     check = fetch_one()
     if check > 0:
         c.execute(
             "SELECT id, filename, filetype, folderid FROM archive.ArchivedChannels"
         )
         posts = fetch_all()
         for post in posts:
             ID = post[0]
             FileName = post[1]
             FileType = post[2]
             FolderID = post[3]
             Drive.upload_to_drive(ID, FolderID, FileName, FileType)
コード例 #9
0
 async def on_message(message):
     try:
         # fetching temporary channels that have delays for removed messages.
         c.execute("SELECT chanID, delay FROM currency.TempChannels")
         temp_channels = fetch_all()
         message_sender = message.author
         message_content = message.clean_content
         message_channel = message.channel
         # check if messages are in a temporary channel
         for temp in temp_channels:
             chan_id = temp[0]
             delay = temp[1]
             if message_channel.id == chan_id:
                 await message.delete(delay=delay)
         if check_message_not_empty(message):
             # check if the message belongs to the bot
             if message_sender.id != client.user.id:
                 if message_content[0] != '%':
                     # it had to be written somewhere :( and I'm not about to pull it from a table
                     if 'n***a' in message_content.lower(
                     ) or 'nigger' in message_content.lower(
                     ) and ':' not in message_content.lower():
                         author_id = message_sender.id
                         # checks how many instances ( should logically only be 0 or 1 )
                         c.execute(
                             "SELECT COUNT(*) FROM currency.Counter WHERE UserID = %s::bigint",
                             (author_id, ))
                         checker = fetch_one()
                         if checker > 0:
                             c.execute(
                                 "SELECT NWord FROM currency.Counter WHERE UserID = %s::bigint",
                                 (author_id, ))
                             current_count = fetch_one()
                             current_count += 1
                             c.execute(
                                 "UPDATE currency.Counter SET NWord = %s WHERE UserID = %s::bigint",
                                 (current_count, author_id))
                         if checker == 0:
                             c.execute(
                                 "INSERT INTO currency.Counter VALUES (%s,%s)",
                                 (author_id, 1))
                         DBconn.commit()
             if get_message_prefix(message) == '%':
                 log.console(
                     f"CMD LOG: ChannelID = {message_channel.id} - {message_sender} || {message_content} "
                 )
             await client.process_commands(message)
     except Exception as e:
         log.console(e)
         DBconn.rollback()
コード例 #10
0
 async def sort(self, ctx):
     """Approve member links with a small sorting game."""
     try:
         keep_going = True
         while keep_going:
             c.execute("SELECT COUNT(*) FROM groupmembers.ScrapedLinks")
             counter = fetch_one()
             if counter == 0:
                 await ctx.send("> **There are no links to sort.**")
                 keep_going = False
             c.execute("SELECT ID,Link FROM groupmembers.ScrapedLinks")
             all_links = fetch_all()
             for data in all_links:
                 data_id = data[0]
                 link = data[1]
                 await ctx.send(
                     f"> {link} **Please respond with the member's ID, delete, or stop**"
                 )
                 check_msg = await self.on_message2(ctx.message, 1)
                 if check_msg == 'delete':
                     c.execute(
                         "DELETE FROM groupmembers.ScrapedLinks WHERE ID = %s",
                         (data_id, ))
                     DBconn.commit()
                     await ctx.send("> **The link has been removed.**")
                 elif check_msg == 'stop':
                     await ctx.send("> **Stopping Sort**")
                     keep_going = False
                     break
                 elif check_msg == 'deleteall':
                     await ctx.send("> **Deleted all links**")
                     c.execute("DELETE FROM groupmembers.ScrapedLinks")
                     DBconn.commit()
                     keep_going = False
                     break
                 else:
                     c.execute(
                         "INSERT INTO groupmembers.imagelinks VALUES (%s,%s)",
                         (link, int(check_msg)))
                     c.execute(
                         "DELETE FROM groupmembers.scrapedlinks WHERE ID = %s",
                         (data_id, ))
                     DBconn.commit()
     except Exception as e:
         log.console(e)
コード例 #11
0
    async def countmember(self, ctx, *, member=""):
        """Shows how many photos of a certain member there are. [Format: %countmember <name>]"""
        async def amount_of_links(member_id, current_full_name,
                                  current_stage_name):
            c.execute(
                "SELECT COUNT(*) FROM groupmembers.ImageLinks WHERE MemberID = %s",
                (member_id, ))
            counter = fetch_one()
            if counter == 0:
                await ctx.send(
                    f"> **There are no results for {current_full_name} ({current_stage_name})**"
                )
            else:
                await ctx.send(
                    f"> **There are {counter} images for {current_full_name} ({current_stage_name}).**"
                )

        if member == "":
            await ctx.send(
                "> **Please specify a member's full name, stage name, or alias.**"
            )
        member = member.replace("_", " ")
        c.execute(
            "SELECT ID, FullName, StageName, Aliases FROM groupmembers.Member")
        all_members = fetch_all()
        for all_member in all_members:
            id = all_member[0]
            full_name = all_member[1]
            stage_name = all_member[2]
            aliases = all_member[3]
            if member.lower() == full_name.lower():
                await amount_of_links(id, full_name, stage_name)
            elif member.lower() == stage_name.lower():
                await amount_of_links(id, full_name, stage_name)
            try:
                aliases = aliases.split(",")
                for alias in aliases:
                    if member.lower() == alias.lower():
                        await amount_of_links(id, full_name, stage_name)
            except:
                pass
コード例 #12
0
 async def scrapeyoutube(self, ctx):
     """Scrape Youtube Video"""
     c.execute("SELECT link FROM currency.links")
     links = fetch_all()
     for link in links:
         c.execute("SELECT LinkID FROM currency.links WHERE Link = %s",
                   (link, ))
         id = fetch_one()
         async with aiohttp.ClientSession() as session:
             async with session.get('{}'.format(link[0])) as r:
                 if r.status == 200:
                     page_html = await r.text()
                     log.console(page_html)
                     page_soup = soup(page_html, "html.parser")
                     view_count = (page_soup.find(
                         "div", {"class": "watch-view-count"})).text
                     # c.execute("INSERT INTO currency.ViewCount VALUES (%s,%s)", (id,datetime.now()))
                     # DBconn.commit()
                     await ctx.send(
                         f"> **Managed to scrape DC SCREAM -- {view_count} -- {datetime.now()}**"
                     )
コード例 #13
0
 async def listchannels(self, ctx):
     """List the channels in your server that are being archived. [Format: %listchannels]"""
     c.execute(
         "SELECT id, channelid, guildid, driveid, name FROM archive.ChannelList"
     )
     all_channels = fetch_all()
     guild_name = ctx.guild.name
     embed = discord.Embed(title=f"Archived {guild_name} Channels",
                           color=0x87CEEB)
     embed.set_author(
         name="Irene",
         url='https://www.youtube.com/watch?v=dQw4w9WgXcQ',
         icon_url=
         'https://cdn.discordapp.com/emojis/693392862611767336.gif?v=1')
     embed.set_footer(
         text="Thanks for using Irene.",
         icon_url=
         'https://cdn.discordapp.com/emojis/683932986818822174.gif?v=1')
     check = False
     for channel in all_channels:
         ID = channel[0]
         ChannelID = channel[1]
         list_channel = (await self.client.fetch_channel(ChannelID)).name
         GuildID = channel[2]
         DriveID = channel[3]
         Name = channel[4]
         if ctx.guild.id == GuildID:
             check = True
             embed.insert_field_at(
                 0,
                 name=list_channel,
                 value=
                 f"https://drive.google.com/drive/folders/{DriveID} | {Name}",
                 inline=False)
             pass
     if check:
         await ctx.send(embed=embed)
     else:
         await ctx.send(
             "> **There are no archived channels on this server.**")
コード例 #14
0
 async def nwordleaderboard(self, ctx):
     """Shows leaderboards for how many times the nword has been said. [Format: %nwl]"""
     embed = discord.Embed(title=f"NWord Leaderboard", color=0xffb6c1)
     embed.set_author(
         name="Irene",
         url='https://www.youtube.com/watch?v=dQw4w9WgXcQ',
         icon_url=
         'https://cdn.discordapp.com/emojis/693392862611767336.gif?v=1')
     embed.set_footer(
         text="Type %nword (user) to view their individual stats.",
         icon_url=
         'https://cdn.discordapp.com/emojis/683932986818822174.gif?v=1')
     c.execute(
         "SELECT UserID, NWord FROM currency.Counter ORDER BY NWord DESC")
     all_members = fetch_all()
     count_loop = 0
     for mem in all_members:
         count_loop += 1
         if count_loop <= 10:
             user_name = (await self.client.fetch_user(mem[0])).name
             embed.add_field(name=f"{count_loop}) {user_name} ({mem[0]})",
                             value=mem[1])
     await ctx.send(embed=embed)
コード例 #15
0
    async def new_task4(self):
        # log.console (self.number)
        self.count_loop += 1
        if self.first_run == 1:
            c.execute("SELECT PostID FROM currency.DCPost")
            number = fetch_one()
            self.first_run = 0
            self.number = number
            self.post_list.append(number)
        if self.error_status == 1:
            if self.tries >= 2 and self.tries < 5:
                self.number += 1
            if self.tries >= 5:
                count_list = (len(self.post_list))
                # log.console (count_list)
                # log.console (self.post_list)
                self.number = self.post_list[count_list - 1]
                # log.console (self.number)
                self.tries = 0
        if self.error_status == 0:
            self.tries = 0
            self.number += 1
            pass
        # log.console (self.number)
        my_url = 'https://dreamcatcher.candlemystar.com/post/{}'.format(self.number)
        async with aiohttp.ClientSession() as session:
            async with session.get('{}'.format(my_url)) as r:
                if r.status == 200:
                    c.execute("DELETE FROM currency.DCPost")
                    c.execute("INSERT INTO currency.DCPost VALUES(%s)", (self.number,))
                    DBconn.commit()
                    self.error_status = 0
                    if self.number not in self.post_list:
                        # log.console("Connection Found")
                        page_html = await r.text()
                        # log.console(await r.text())
                        page_soup = soup(page_html, "html.parser")
                        username = (page_soup.find("div", {"class": "card-name"})).text
                        # await ctx.send(username)
                        if username in self.list:
                            Gahyeon = self.list[0]
                            Siyeon = self.list[1]
                            Yoohyeon = self.list[2]
                            JiU = self.list[3]
                            SuA = self.list[4]
                            DC = self.list[5]
                            Dami = self.list[6]
                            Handong = self.list[7]
                            image_url = (page_soup.findAll("div", {"class": "imgSize width"}))
                            image_links = []
                            for image in image_url:
                                new_image_url = image.img["src"]
                                DC_Date = new_image_url[41:49]
                                unique_id = new_image_url[55:87]
                                file_format = new_image_url[93:]
                                HD_Link = f'https://file.candlemystar.com/post/{DC_Date}{unique_id}{file_format}'
                                image_links.append(HD_Link)
                                async with session.get(HD_Link) as resp:
                                    fd = await aiofiles.open(
                                        'DreamHD/{}'.format(f"{unique_id[:8]}{file_format}"), mode='wb')
                                    await fd.write(await resp.read())
                                    await fd.close()
                            another_list = []
                            new_count = -1
                            final_image_list = []
                            for image in image_url:
                                new_count += 1
                                new_image_url = image.img["src"]
                                file_name = new_image_url[82:]
                                async with session.get(new_image_url) as resp:
                                    fd = await aiofiles.open('DCApp/{}'.format(file_name), mode='wb')
                                    await fd.write(await resp.read())
                                    await fd.close()
                                    file_size = (os.path.getsize(f'DCApp/{file_name}'))
                                    if file_size <= 20000:
                                        keep_going = True
                                        loop_count = 0
                                        while keep_going:
                                            log.console(f"Stuck in a loop {loop_count}")
                                            loop_count += 1
                                            try:
                                                os.unlink(f'DCApp/{file_name}')
                                            except Exception as e:
                                                log.console(e)
                                            fd = await aiofiles.open('DCApp/{}'.format(file_name), mode='wb')
                                            await fd.write(await resp.read())
                                            await fd.close()
                                            file_size = (os.path.getsize(f'DCApp/{file_name}'))
                                            if file_size > 20000:
                                                another_list.append(file_name)
                                                keep_going = False
                                            if loop_count == 30:
                                                try:
                                                    final_image_list.append(image_links[new_count])
                                                    os.unlink(f'DCApp/{file_name}')
                                                    keep_going = False
                                                except Exception as e:
                                                    log.console(e)
                                                    keep_going = False
                                    elif file_size > 20000:
                                        another_list.append(file_name)
                                    c.execute("DELETE FROM currency.DCUrl")
                                    c.execute("INSERT INTO currency.DCUrl VALUES(%s)", (my_url,))
                                    DBconn.commit()
                            video_list = (page_soup.findAll("div", {"class": "swiper-slide img-box video-box width"}))
                            count_numbers = 0
                            video_name_list = []
                            bat_name_list = []
                            for video in video_list:
                                count_numbers += 1
                                new_video_url = video.source["src"]
                                bat_name = "{}DC.bat".format(count_numbers)
                                bat_name_list.append(bat_name)
                                ab = open("Videos\{}".format(bat_name), "a+")
                                video_name = "{}DCVideo.mp4".format(count_numbers)
                                info = 'ffmpeg -i "{}" -c:v libx264 -preset slow -crf 22 "Videos/{}"'.format(new_video_url,
                                                                                                             video_name)
                                video_name_list.append(video_name)
                                ab.write(info)
                                ab.close()
                            for bat_name in bat_name_list:
                                # open bat file
                                check_bat = await asyncio.create_subprocess_exec("Videos\\{}".format(bat_name),
                                                                                 stderr=asyncio.subprocess.PIPE)
                                await check_bat.wait()
                            c.execute("SELECT ServerID FROM currency.DreamCatcher")
                            a1 = fetch_all()
                            for channel in a1:
                                channel = channel[0]
                                DC_Videos = []
                                try:
                                    if len(video_name_list) != 0:
                                        for video_name in video_name_list:
                                            dc_video = discord.File(fp='Videos/{}'.format(video_name), filename=video_name)
                                            DC_Videos.append(dc_video)
                                except Exception as e:
                                    log.console (e)
                                    pass
                                DC_Photos = []
                                try:
                                    if len(another_list) != 0:
                                        for file_name in another_list:
                                            dc_photo = discord.File(fp='DCApp/{}'.format(file_name),
                                                                    filename=file_name)
                                            DC_Photos.append(dc_photo)
                                except Exception as e:
                                    log.console (e)
                                    pass
                                channel = self.client.get_channel(channel)
                                # 'NoneType' object has no attribute 'send' -- Channel does not exist (catching error)
                                try:
                                    member_id = None
                                    member_name = None
                                    if username == Gahyeon:
                                        member_name = "Gahyeon"
                                        member_id = 163
                                        await channel.send(">>> **New Gahyeon Post\n<{}>**".format(my_url))
                                    if username == Siyeon:
                                        member_name = "Siyeon"
                                        member_id = 159
                                        await channel.send(">>> **New Siyeon Post\n<{}>**".format(my_url))
                                    if username == Yoohyeon:
                                        member_name = "Yoohyeon"
                                        member_id = 161
                                        await channel.send(">>> **New Yoohyeon Post\n<{}>**".format(my_url))
                                    if username == JiU:
                                        member_name = "JIU"
                                        member_id = 157
                                        await channel.send(">>> **New JiU Post\n<{}>**".format(my_url))
                                    if username == SuA:
                                        member_name = "SUA"
                                        member_id = 158
                                        await channel.send(">>> **New SuA Post\n<{}>**".format(my_url))
                                    if username == DC:
                                        member_name = "DC"
                                        await channel.send(">>> **New DreamCatcher Post\n<{}>**".format(my_url))
                                    if username == Dami:
                                        member_name = "Dami"
                                        member_id = 162
                                        await channel.send(">>> **New Dami Post\n<{}>**".format(my_url))
                                    if username == Handong:
                                        member_name = "Handong"
                                        member_id = 160
                                        await channel.send(">>> **New Handong Post\n<{}>**".format(my_url))
                                    if self.already_added == 1:
                                            for link in image_links:
                                                try:
                                                    if member_id is not None:
                                                        c.execute("INSERT INTO groupmembers.imagelinks VALUES (%s,%s)", (link, member_id))
                                                    c.execute("INSERT INTO currency.DCHDLinks VALUES (%s,%s,%s)", (link, member_name, self.number))
                                                    DBconn.commit()
                                                    self.already_added = 1
                                                except Exception as e:
                                                    log.console(e)
                                                    pass
                                except Exception as e:
                                    log.console(e)
                                    pass
                                try:
                                    if len(another_list) != 0:
                                        for dc_photo in DC_Photos:
                                            await channel.send(file=dc_photo)
                                    if len(video_name_list) != 0:
                                        for video in video_name_list:
                                            await channel.send(file=video)
                                    if len(final_image_list) != 0:
                                        for link in final_image_list:
                                            await channel.send(link)
                                except Exception as e:
                                    log.console (e)
                                    pass
                            all_videos = os.listdir('Videos')
                            for video in all_videos:
                                try:
                                    os.unlink('Videos/{}'.format(video))
                                except Exception as e:
                                    log.console(e)
                                    pass
                            all_photos = os.listdir('DCApp')
                            for photo in all_photos:
                                try:
                                    os.unlink('DCApp/{}'.format(photo))
                                except Exception as e:
                                    log.console (e)
                                    pass
                        else:
                            log.console("Passing Post from POST #{}".format(self.number))
                            # await ctx.send(">>> **Passing Post from {}, POST #{}**".format(username, self.number))
                    self.post_list.append(self.number)

                elif r.status == 304:
                    log.console("> **Access Denied - {}**".format(self.number))
                elif r.status == 404:
                    self.tries += 1
                    if self.count_loop % 500 == 0:
                        log.console("Error 404. {} was not Found.".format(self.number))
                    self.error_status = 1
                    pass
                else:
                    log.console(r.status)
コード例 #16
0
    async def addhistory(self,
                         ctx,
                         year: int = None,
                         month: int = None,
                         day: int = None):
        """Add all of the previous images from a text channel to google drive."""
        if (year and month and day) is not None:
            after = datetime(year, month, day)
        else:
            after = None

        async def history(guild_id, drive_id):
            try:
                async for message in ctx.channel.history(limit=None,
                                                         after=after):
                    if len(message.attachments) > 0:
                        for file in message.attachments:
                            url = file.url
                            if "%27%3E" in url:
                                pos = url.find("%27%3E")
                                url = url[0:pos - 1]
                            if ":large" in url:
                                pos = url.find(":large")
                                url = url[0:pos - 1]
                            await self.download_url(url, drive_id,
                                                    ctx.channel.id)

                    if len(message.embeds) > 0:
                        for embed in message.embeds:
                            if str(embed.url) == "Embed.Empty":
                                pass
                            else:
                                url = embed.url
                                if "%27%3E" in url:
                                    pos = url.find("%27%3E")
                                    url = url[0:pos - 1]
                                if ":large" in url:
                                    pos = url.find(":large")
                                    url = url[0:pos - 1]
                                await self.download_url(
                                    url, drive_id, ctx.channel.id)

                    pass
            except Exception as e:
                log.console(e)
                pass

        check = False
        c.execute(
            "SELECT channelid, guildid, driveid FROM archive.ChannelList")
        channels = fetch_all()
        for channel in channels:
            ChannelID = channel[0]
            GuildID = channel[1]
            DriveID = channel[2]
            if ctx.channel.id == ChannelID:
                check = True
                await ctx.send(
                    "> **Starting to check history... to prevent bot lag, an external program uploads them every 60 seconds.**"
                )
                await history(GuildID, DriveID)
                await self.deletephotos()
                await ctx.send(
                    "> **Successfully added history of this text channel. They will be uploaded shortly.**"
                )
        if not check:
            await ctx.send(
                "> **This channel is not currently being archived.**")
コード例 #17
0
    async def on_message(self, message, owner=0):
        if owner == 1:
            try:

                def check(m):
                    return m.channel == message.channel and m.author.id == self.bot_owner_id

                msg = await self.client.wait_for('message',
                                                 timeout=60,
                                                 check=check)
                if msg.content.lower() == "confirm" or msg.content.lower(
                ) == "confirmed":
                    return True
            except asyncio.TimeoutError:
                return False

        if owner == 0:
            if not message.author.bot:
                try:
                    c.execute(
                        "SELECT id, channelid, guildid, driveid, name FROM archive.channellist"
                    )
                    all_channels = fetch_all()
                    for channel in all_channels:
                        ID = channel[0]
                        ChannelID = channel[1]
                        GuildID = channel[2]
                        drive_id = channel[3]
                        Name = channel[4]
                        if message.channel.id == ChannelID:
                            if len(message.attachments) > 0:
                                for file in message.attachments:
                                    url = file.url
                                    if "%27%3E" in url:
                                        pos = url.find("%27%3E")
                                        url = url[0:pos - 1]
                                    if ":large" in url:
                                        pos = url.find(":large")
                                        url = url[0:pos]
                                    await self.download_url(
                                        url, drive_id, message.channel.id)
                                # quickstart.Drive.checker()
                            if len(message.embeds) > 0:
                                for embed in message.embeds:
                                    if str(embed.url) == "Embed.Empty":
                                        pass
                                    else:
                                        url = embed.url
                                        if "%27%3E" in url:
                                            pos = url.find("%27%3E")
                                            url = url[0:pos - 1]
                                        if ":large" in url:
                                            pos = url.find(":large")
                                            url = url[0:pos]
                                        await self.download_url(
                                            url, drive_id, message.channel.id)
                                    # quickstart.Drive.checker()
                            await self.deletephotos()
                except Exception as e:
                    # log.console(e)
                    pass
コード例 #18
0
    async def joingame(self, ctx, gameid=0, amount=0):
        """Join a game [Format: %joingame (gameid) (bid)] [Aliases: jg]"""
        if amount >= 0:
            if gameid == 0:
                await ctx.send(
                    "> **Please include the game id in your command. [Format: %jg (gameid) (bid)]**",
                    delete_after=40)
            if gameid != 0:
                try:
                    rules = "**Each Player gets 2 cards.\nIn order to get blackjack, your final value must equal 21.\nIf Player1 exceeds 21 and Player2 doesn't, Player1 busts and Player2 wins the game.\nYou will have two options.\nThe first option is to %Hit, which means to grab another card.\nThe second option is to %stand to not pick up anymore cards.\nEach Player will play one at a time so think ahead!\nIf both players bust, Player closest to 21 wins!\nNumber cards are their values.\nAces can be 1 or 11 depending on the scenario.\nJack, Queen, and King are all worth 10. **"
                    player_2 = ctx.author.id
                    player2_bid = amount
                    game_id = gameid
                    c.execute(
                        "SELECT Player1 FROM currency.Games WHERE GameID = %s",
                        (game_id, ))
                    check = fetch_one()
                    c.execute(
                        "SELECT Player2 FROM currency.Games WHERE GameID = %s",
                        (game_id, ))
                    check2 = fetch_one()
                    c.execute(
                        "SELECT COUNT(*) FROM currency.Games WHERE Player1 = %s OR Player2 = %s",
                        (player_2, player_2))
                    count_checker = fetch_one()
                    if count_checker >= 1:
                        await ctx.send(
                            "> **You are already in a pending/active game. Please type %endgame to end your current game.**",
                            delete_after=40)
                    if count_checker == 0:
                        if check2 != 0:
                            await ctx.send(
                                "> **This game has already started.**",
                                delete_after=40)
                        if check2 == 0:
                            if check == player_2:
                                await ctx.send(
                                    "> **You are already in this game.**",
                                    delete_after=40)
                            if check != player_2:
                                c.execute(
                                    "SELECT count(UserID) FROM currency.Currency WHERE USERID = %s",
                                    (player_2, ))
                                count = fetch_one()
                                if count == 0:
                                    await ctx.send(
                                        "> **You are not currently registered. Please type %register to register.**",
                                        delete_after=40)
                                if count == 1:
                                    c.execute(
                                        "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                        (player_2, ))
                                    current_amount = int(fetch_one())
                                    if amount > current_amount:
                                        await ctx.send(
                                            "> **You do not have enough money to give!**",
                                            delete_after=40)
                                    if amount <= current_amount:
                                        c.execute(
                                            "UPDATE currency.Games SET Player2 = %s, Bid2 = %s WHERE GameID = %s",
                                            (player_2, player2_bid, game_id))
                                        DBconn.commit()
                                        c.execute(
                                            "SELECT Bid1, Bid2 FROM currency.Games Where GameID = %s",
                                            (game_id, ))
                                        total_1 = fetch_all()
                                        for a in total_1:
                                            x = a[0]
                                            y = a[1]
                                        total = x + y
                                        await ctx.send(
                                            "> **Starting BlackJack with a total bid of {:,} Dollars.**"
                                            .format(total),
                                            delete_after=60)
                                        await ctx.send(">>> {}".format(rules),
                                                       delete_after=60)
                                        new_list = []
                                        file_1 = []
                                        file_2 = []
                                        for i in range(0, 4):
                                            random_card = randint(1, 52)
                                            while random_card in new_list:
                                                random_card = randint(1, 52)
                                            new_list.append(random_card)
                                        for i in range(0, 2):
                                            c.execute(
                                                "SELECT cardname FROM currency.CardValues WHERE CardID = %s",
                                                (new_list[i], ))
                                            card_name = fetch_one()
                                            c.execute(
                                                "SELECT value FROM currency.CardValues WHERE CardID = %s",
                                                (new_list[i], ))
                                            card_value = fetch_one()
                                            c.execute(
                                                "SELECT Score1 FROM currency.Games WHERE GameID = %s",
                                                (game_id, ))
                                            current_val = fetch_one()
                                            c.execute(
                                                "INSERT INTO currency.BlackJack VALUES (%s, %s, %s)",
                                                (game_id, new_list[i], 1))
                                            tot1 = current_val + card_value
                                            c.execute(
                                                "UPDATE currency.Games SET Score1 = %s WHERE GameID = %s",
                                                (tot1, game_id))
                                            card_1 = discord.File(
                                                fp='Cards/{}.jpg'.format(
                                                    new_list[i]),
                                                filename='{}.jpg'.format(
                                                    new_list[i]),
                                                spoiler=True)
                                            file_1.append(card_1)
                                            DBconn.commit()
                                        for i in range(2, 4):
                                            c.execute(
                                                "SELECT cardname FROM currency.CardValues WHERE CardID = %s",
                                                (new_list[i], ))
                                            card_name = fetch_one()
                                            c.execute(
                                                "SELECT value FROM currency.CardValues WHERE CardID = %s",
                                                (new_list[i], ))
                                            card_value = fetch_one()
                                            c.execute(
                                                "SELECT Score2 FROM currency.Games WHERE GameID = %s",
                                                (game_id, ))
                                            current_val = fetch_one()
                                            c.execute(
                                                "INSERT INTO currency.BlackJack VALUES (%s, %s, %s)",
                                                (game_id, new_list[i], 2))
                                            tot = current_val + card_value
                                            c.execute(
                                                "UPDATE currency.Games SET Score2 = %s WHERE GameID = %s",
                                                (tot, game_id))
                                            card_2 = discord.File(
                                                fp='Cards/{}.jpg'.format(
                                                    new_list[i]),
                                                filename='{}.jpg'.format(
                                                    new_list[i]),
                                                spoiler=True)
                                            file_2.append(card_2)
                                            DBconn.commit()
                                        c.execute(
                                            "SELECT Player1 FROM currency.Games WHERE GameID = %s",
                                            (game_id, ))
                                        player_1 = fetch_one()
                                        await ctx.send(
                                            "<@{}>'s current score is ||{}||".
                                            format(player_1, tot1),
                                            files=file_1,
                                            delete_after=120)
                                        await ctx.send(
                                            "<@{}>'s current score is ||{}||".
                                            format(player_2, tot),
                                            files=file_2,
                                            delete_after=120)
                                        self.aces = 0
                                        self.game_list = []
                                        self.game_list.append(game_id)
                                        # self._start_tasks()
                                        self._start_tasks(
                                            ctx, game_id, player_1, player_2)
                                        # self.bgloop.start(ctx, game_id, player_1, player_2)

                                if count > 1:
                                    await ctx.send(
                                        "> **There is an error with the database. Please report to an administrator**",
                                        delete_after=40)
                except Exception as e:
                    log.console(e)
                    await ctx.send(
                        "> **Failed to join. This game does not exist.**",
                        delete_after=40)
        elif amount < 0:
            await ctx.send("> **You cannot bet a negative number**")
コード例 #19
0
 async def hit(self, ctx):
     """Pick A Card [Format: %hit]"""
     userid = ctx.author.id
     try:
         random_card = randint(1, 52)
         c.execute(
             "SELECT GameID FROM currency.Games WHERE Player1 = %s OR Player2 = %s",
             (userid, userid))
         game_id = fetch_one()
         c.execute(
             "SELECT Player1,Player2 FROM currency.Games WHERE Player1 = %s OR Player2 = %s",
             (userid, userid))
         player = c.fetchone()
         c.execute("SELECT CardID FROM currency.BlackJack WHERE GameID =%s",
                   (game_id, ))
         cards = fetch_all()
         while random_card in cards:
             random_card = randint(1, 52)
         Player1 = player[0]
         Player2 = player[1]
         c.execute("SELECT Stand FROM currency.Games WHERE GameID = %s",
                   (game_id, ))
         current_stand = str(fetch_one())
         keep_going = True
         if userid == Player1:
             xyz = 1
             if current_stand[0] == 2:
                 keep_going = False
         if userid == Player2:
             xyz = 2
             if current_stand[1] == 2:
                 keep_going = False
         if keep_going == True:
             c.execute("INSERT INTO currency.BlackJack VALUES (%s, %s, %s)",
                       (game_id, random_card, xyz))
             abc = discord.File(fp='Cards/{}.jpg'.format(random_card),
                                filename='{}.jpg'.format(random_card),
                                spoiler=True)
             c.execute(
                 "SELECT value FROM currency.CardValues WHERE CardID = %s",
                 (random_card, ))
             card_value = fetch_one()
             c.execute(
                 "SELECT Score{} FROM currency.Games WHERE GameID = %s".
                 format(xyz), (game_id, ))
             current_val = fetch_one()
             tot = current_val + card_value
             c.execute(
                 "SELECT COUNT(*) FROM currency.BlackJack WHERE CardID = %s AND Position = %s AND GameID = %s",
                 (1, xyz, game_id))
             check_for_ace1 = fetch_one()
             c.execute(
                 "SELECT COUNT(*) FROM currency.BlackJack WHERE CardID = %s AND Position = %s AND GameID = %s",
                 (14, xyz, game_id))
             check_for_ace2 = fetch_one()
             c.execute(
                 "SELECT COUNT(*) FROM currency.BlackJack WHERE CardID = %s AND Position = %s AND GameID = %s",
                 (27, xyz, game_id))
             check_for_ace3 = fetch_one()
             c.execute(
                 "SELECT COUNT(*) FROM currency.BlackJack WHERE CardID = %s AND Position = %s AND GameID = %s",
                 (40, xyz, game_id))
             check_for_ace4 = fetch_one()
             self.aces = 0
             if check_for_ace1 == 1:
                 self.aces += 1
                 current = 1
                 c.execute(
                     "UPDATE currency.BlackJack SET Position = %s WHERE GameID = %s AND CardID = %s",
                     (3, game_id, 1))
             if check_for_ace2 == 1:
                 self.aces += 1
                 current = 1
                 c.execute(
                     "UPDATE currency.BlackJack SET Position = %s WHERE GameID = %s AND CardID = %s",
                     (3, game_id, 14))
             if check_for_ace3 == 1:
                 self.aces += 1
                 current = 1
                 c.execute(
                     "UPDATE currency.BlackJack SET Position = %s WHERE GameID = %s AND CardID = %s",
                     (3, game_id, 27))
             if check_for_ace4 == 1:
                 self.aces += 1
                 current = 1
                 c.execute(
                     "UPDATE currency.BlackJack SET Position = %s WHERE GameID = %s AND CardID = %s",
                     (3, game_id, 40))
             self.ace_list = []
             if self.aces >= 1:
                 self.ace_list.append(userid)
                 self.ace_list.append(self.aces)
                 self.ace2_list.append(self.ace_list)
             for ace in self.ace2_list:
                 user = ace[0]
                 card_ace = ace[1]
                 if ctx.author.id == user and tot > 21 and card_ace >= 1:
                     ace[1] -= 1
                     if ace[1] == 0:
                         self.ace2_list.remove(ace)
                     tot = tot - 10
             await ctx.send("<@{}>'s current score is ||{}||".format(
                 userid, tot),
                            file=abc,
                            delete_after=120)
             c.execute(
                 "UPDATE currency.Games SET Score{} = %s WHERE GameID = %s".
                 format(xyz), (tot, game_id))
             DBconn.commit()
     except Exception as e:
         log.console(e)
         await ctx.send("> **You are not currently playing a game.**",
                        delete_after=40)
         pass