Ejemplo n.º 1
0
 async def tenor(self, ctx, keyword, limit=1):
     """Connection to tenor API // Sends Links of gifs to Database. // dashes are spaces between words"""
     # base_url = f'https://api.tenor.com/v1/search?<parameters>'
     # https://tenor.com/developer/dashboard
     try:
         url = f'https://api.tenor.com/v1/search?q={keyword}&key={keys.tenor_key}&limit={limit}'
         async with aiohttp.ClientSession() as session:
             async with session.get(url) as r:
                 if r.status == 200:
                     content = await r.content.read()
                     gifs = json.loads(content)
                     count = 0
                     for key in gifs['results']:
                         count += 1
                         # await ctx.send((key['url']))
                         url = key['url']
                         c.execute(
                             "INSERT INTO groupmembers.ScrapedLinks VALUES (%s)",
                             (url, ))
                     await ctx.send(
                         f"> **{count} link(s) for {keyword} were added to the Database.**"
                     )
                     DBconn.commit()
     except Exception as e:
         log.console(e)
Ejemplo n.º 2
0
 async def addalias(self, ctx, alias, *, member):
     """Add alias to a member [Format: %addalias (alias) (member full name)]"""
     try:
         c.execute(
             "SELECT COUNT(*) FROM groupmembers.Member WHERE FullName = %s",
             (member, ))
         counter = fetch_one()
         if counter == 0:
             await ctx.send("> **That person does not exist.**")
         else:
             c.execute(
                 "SELECT Aliases FROM groupmembers.Member WHERE FullName = %s",
                 (member, ))
             current_aliases = fetch_one()
             if current_aliases == "NULL":
                 new_aliases = alias
             else:
                 new_aliases = f"{current_aliases},{alias.lower()}"
             c.execute(
                 "UPDATE groupmembers.Member SET Aliases = %s WHERE FullName = %s",
                 (new_aliases, member))
             DBconn.commit()
             await ctx.send(f"> **Added Alias: {alias} to {member}**")
     except Exception as e:
         await ctx.send(e)
         log.console(e)
Ejemplo n.º 3
0
 async def endgame(self, ctx):
     """End your current game [Format: %endgame] [Aliases: eg]"""
     try:
         c.execute(
             "SELECT currency.GameID FROM Games WHERE Player1 = %s OR Player2 = %s",
             (ctx.author.id, ctx.author.id))
         game_id = fetch_one()
         c.execute(
             "DELETE FROM currency.Games WHERE Player1 = %s OR Player2 = %s",
             (ctx.author.id, ctx.author.id))
         c.execute("DELETE FROM currency.BlackJack WHERE GameID = %s",
                   (game_id, ))
         DBconn.commit()
         for task in self.tasks:
             # await ctx.send(task)
             x = task[0]
             y = task[1]
             z = task[2]
             if ctx.author.id == y or ctx.author.id == z:
                 x.stop()
                 self.tasks.remove(task)
         await ctx.send(
             "> **You have been removed from your current game.**",
             delete_after=5)
         self.count = 0
     except:
         await ctx.send("> **You are not currently in a running game.**",
                        delete_after=40)
Ejemplo n.º 4
0
    async def download_url(self, url, drive_id, channel_id):
        try:
            async with aiohttp.ClientSession() as session:
                async with session.get(url) as r:
                    check = False
                    if r.status == 200:
                        unique_id = randint(0, 1000000000000)
                        unique_id2 = randint(0, 1000)
                        unique_id3 = randint(0, 500)
                        src = url[len(url) - 4:len(url)]
                        checkerx = url.find(":large")
                        if checkerx != -1:
                            src = url[len(url) - 10:len(url) - 6]
                            url = f"{url[0:checkerx-1]}:orig"

                        src2 = url.find('?format=')
                        if src2 != -1:
                            check = True
                            src = f".{url[src2+8:src2+11]}"
                            url = f"{url[0:src2-1]}{src}:orig"
                        if src == ".jpg" or src == ".gif" or src == '.png' or check:
                            file_name = f"1_{unique_id}_{unique_id2}_{unique_id3}{src}"
                            fd = await aiofiles.open(
                                'Photos/{}'.format(file_name), mode='wb')
                            await fd.write(await r.read())
                            await fd.close()
                            c.execute(
                                "INSERT INTO archive.ArchivedChannels VALUES(%s,%s,%s,%s)",
                                (file_name, src, drive_id, channel_id))
                            DBconn.commit()
                        # quickstart.Drive.checker()
        except Exception as e:
            log.console(e)
            pass
Ejemplo n.º 5
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.**")
Ejemplo n.º 6
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 = []
Ejemplo n.º 7
0
 async def removeurl(self, ctx, link):
     """Remove url from youtube videos [Format: %removeurl (link)]"""
     try:
         c.execute("DELETE FROM currency.Links WHERE Link = %s", (link, ))
         DBconn.commit()
         await ctx.send("> **That video has been deleted**")
     except:
         await ctx.send("> **That video is not being tracked.**")
Ejemplo n.º 8
0
 async def logremove(self, ctx):
     """Stop logging the current text channel."""
     if await check_if_logged(channel_id=ctx.channel.id):
         c.execute("DELETE FROM logging.channels WHERE channelid = %s", (ctx.channel.id,))
         DBconn.commit()
         await ctx.send("> **This channel is no longer being logged.**")
     else:
         await ctx.send(f"> **This channel is not being logged.**")
Ejemplo n.º 9
0
    async def stand(self, ctx):
        """Keep Your Cards [Format: %stand]"""
        userid = ctx.author.id
        try:
            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
            Player1 = player[0]
            Player2 = player[1]
            c.execute("SELECT Stand FROM currency.GAMES WHERE GameID = %s",
                      (game_id, ))
            stand = str(fetch_one())
            if userid == Player1:
                xyz = 1
                if stand == '11' or stand == '12':
                    if stand[1] == '1':
                        new_stand = 21
                    if stand[1] == '2':
                        new_stand = 22
                    c.execute(
                        "UPDATE currency.Games SET Stand = %s WHERE GameID = %s",
                        (
                            new_stand,
                            game_id,
                        ))
                    DBconn.commit()

            if userid == Player2:
                xyz = 2
                if stand == '11' or stand == '21':
                    if stand[0] == '1':
                        new_stand = 12
                    if stand[0] == '2':
                        new_stand = 22
                    c.execute(
                        "UPDATE currency.Games SET Stand = %s WHERE GameID = %s",
                        (
                            new_stand,
                            game_id,
                        ))
                    DBconn.commit()
            c.execute(
                "SELECT Score{} FROM currency.Games WHERE GameID = %s".format(
                    xyz), (game_id, ))
            current_val = fetch_one()
            await ctx.send(
                "> **<@{}> has finalized their deck with a total of ||{}|| points.**"
                .format(userid, current_val),
                delete_after=40)
        except:
            await ctx.send("> **You are not currently in a game.**",
                           delete_after=40)
Ejemplo n.º 10
0
 async def addurl(self, ctx, link):
     """Add url to youtube videos [Format: %addurl (link)]"""
     if 'youtube.com' in link or 'youtu.be' in link:
         try:
             c.execute("INSERT INTO currency.Links VALUES(%s)", (link, ))
             DBconn.commit()
             await ctx.send("> **That video is now being traced**")
         except Exception as e:
             log.console(e)
             await ctx.send("> **That video is already being tracked.**")
Ejemplo n.º 11
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()
Ejemplo n.º 12
0
 async def logadd(self, ctx):
     """Start logging the current text channel."""
     if await check_if_logged(server_id=ctx.guild.id):
         if not await check_if_logged(channel_id=ctx.channel.id):
             c.execute("SELECT COUNT(*) FROM logging.servers WHERE channelid = %s", (ctx.channel.id,))
             if fetch_one() == 0:
                 logging_id = await get_logging_id(ctx.guild.id)
                 c.execute("INSERT INTO logging.channels (channelid, server) VALUES(%s, %s)", (ctx.channel.id, logging_id))
                 DBconn.commit()
                 await ctx.send(f"> **This channel is now being logged.**")
             else:
                 await ctx.send(f"> **This channel can not be logged since log messages are sent here.**")
         else:
             await ctx.send(f"> **This channel is already being logged.**")
     else:
         await ctx.send(f"> **The server must be logged in order to log a channel.**")
Ejemplo n.º 13
0
 async def clearnword(self, ctx, user: discord.Member = "@user"):
     """Clear A User's Nword Counter [Format: %clearnword @user]"""
     if user == "@user":
         await ctx.send("> **Please @ a user**")
     if user != "@user":
         c.execute(
             "SELECT COUNT(*) FROM currency.Counter WHERE UserID = %s",
             (user.id, ))
         checker = fetch_one()
         if checker > 0:
             c.execute("DELETE FROM currency.Counter where UserID = %s",
                       (user.id, ))
             await ctx.send("**> Cleared.**")
             DBconn.commit()
         if checker == 0:
             await ctx.send(
                 f"> **<@{user.id}> has not said the N-Word a single time!**"
             )
Ejemplo n.º 14
0
 def upload_to_drive(ID, folder_id, file_name, file_type):
     try:
         drive_service = Drive.get_drive_connection()
         file_metadata = {'name': file_name, 'parents': [folder_id]}
         if len(file_type) == 4:
             file_type = file_type[1:3]
             # print(file_name)
             file_location = f'Photos/{file_name}'
             media = MediaFileUpload(file_location)
             file = drive_service.files().create(body=file_metadata,
                                                 media_body=media,
                                                 fields='id').execute()
         c.execute("DELETE FROM archive.ArchivedChannels WHERE ID = %s",
                   (ID, ))
         DBconn.commit()
         # print ('File ID: %s'% file.get('id'))
         # link_addon = file.get('id')
     except Exception as e:
         log.console(e)
Ejemplo n.º 15
0
 async def deletechannel(self, ctx):
     """Stop the current channel from being archived [Format: %deletechannel]"""
     try:
         c.execute(
             "SELECT COUNT(*) FROM archive.ChannelList WHERE ChannelID = %s",
             (ctx.channel.id, ))
         count = fetch_one()
         if count == 0:
             await ctx.send(
                 "> **This channel is not currently being archived.**")
         else:
             c.execute(
                 "DELETE FROM archive.ChannelList WHERE ChannelID = %s",
                 (ctx.channel.id, ))
             DBconn.commit()
             await ctx.send("> **This channel is no longer being archived**"
                            )
     except Exception as e:
         log.console(e)
         await ctx.send("> **There was an error.**")
Ejemplo n.º 16
0
 async def get_photos(self, url, member, groups, stage_name, aliases):
     try:
         if aliases != "NULL":
             aliases = aliases.lower()
         c.execute(
             "SELECT COUNT(*) FROM groupmembers.Member WHERE FullName = %s",
             (member, ))
         count = fetch_one()
         if count == 0:
             c.execute(
                 "INSERT INTO groupmembers.Member VALUES (%s,%s,%s,%s)",
                 (member, stage_name, groups, aliases))
             DBconn.commit()
             c.execute(
                 "SELECT ID FROM groupmembers.Member WHERE FullName = %s",
                 (member, ))
             id = fetch_one()
             c.execute("INSERT INTO groupmembers.ImageLinks VALUES (%s,%s)",
                       (url, id))
             DBconn.commit()
         else:
             c.execute(
                 "SELECT ID FROM groupmembers.Member WHERE FullName = %s",
                 (member, ))
             id = fetch_one()
             c.execute("INSERT INTO groupmembers.ImageLinks VALUES (%s,%s)",
                       (url, id))
         log.console(f"Added {url} for {member}")
     except Exception as e:
         # most likely unique constraint failed.
         log.console(f"{e} {url} for {member}")
         pass
     DBconn.commit()
Ejemplo n.º 17
0
 async def updates(self, ctx,*, solution=""):
     """Send DC Updates to your current text channel [Format: %updates] | To Stop : [Format: %updates stop]"""
     channel = ctx.channel.id
     if solution == "stop":
         c.execute("SELECT COUNT(*) From currency.DreamCatcher WHERE ServerID = %s",(channel,))
         counter = fetch_one()
         if counter == 1:
             await ctx.send ("> **This channel will no longer receive updates.**")
             c.execute("DELETE FROM currency.DreamCatcher WHERE ServerID = %s",(channel,))
             DBconn.commit()
         if counter == 0:
             await ctx.send("> **This channel does not currently receive updates.**")
     if solution != "stop":
         c.execute("SELECT COUNT(*) From currency.DreamCatcher WHERE ServerID = %s", (channel,))
         counter = fetch_one()
         if counter == 1:
             await ctx.send ("> **This channel already receives DC Updates**")
         if counter == 0:
             channel_name = self.client.get_channel(channel)
             await ctx.send("> **I Will Post All DC Updates In {}**".format(channel_name))
             c.execute("INSERT INTO currency.DreamCatcher VALUES (%s)",(channel,))
             DBconn.commit()
Ejemplo n.º 18
0
 async def removealias(self, ctx, alias, *, member):
     """Add alias to a member [Format: %addalias (alias) (member full name)]"""
     try:
         c.execute(
             "SELECT COUNT(*) FROM groupmembers.Member WHERE FullName = %s",
             (member, ))
         count = fetch_one()
         if count == 0:
             await ctx.send("> **That person does not exist.**")
         else:
             c.execute(
                 "SELECT Aliases FROM groupmembers.Member WHERE FullName = %s",
                 (member, ))
             current_aliases = fetch_one()
             if current_aliases == "NULL":
                 await ctx.send("> **That alias does not exist**")
             else:
                 check = current_aliases.find(alias.lower(), 0)
                 if check == -1:
                     await ctx.send(f"> **Could not find alias: {alias}**")
                 else:
                     new_aliases = ""
                     alias_list = current_aliases.split(',')
                     for alias2 in alias_list:
                         if alias.lower() != alias2.lower():
                             new_aliases += f"{alias2.lower()},"
                     if new_aliases == "" or new_aliases == ",":
                         new_aliases = "NULL"
                     if new_aliases[len(new_aliases) - 1] == ',':
                         new_aliases = new_aliases[0:len(new_aliases) - 2]
                     c.execute(
                         "UPDATE groupmembers.Member SET Aliases = %s WHERE FullName = %s",
                         (new_aliases, member))
                     DBconn.commit()
                     await ctx.send(
                         f"> **Alias: {alias} was removed from {member}.**")
     except Exception as e:
         await ctx.send(e)
         log.console(e)
Ejemplo n.º 19
0
 async def addcards(self, ctx):
     """Fill The CardValues Table with Cards [Format: %addcards]"""
     c.execute("DELETE FROM currency.CardValues")
     suitName = ("Hearts", "Diamonds", "Spades", "Clubs")
     rankName = ("Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
                 "Eight", "Nine", "Ten", "Jack", "Queen", "King")
     cardvalues = [
         11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11, 2, 3, 4, 5, 6, 7,
         8, 9, 10, 10, 10, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
         11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10
     ]
     cards = []
     for suit in suitName[0:4]:
         for rank in rankName[0:13]:
             cards += [("{} of {}".format(rank, suit))]
     countx = -1
     for card in cards:
         countx += 1
         c.execute("INSERT INTO currency.CardValues VALUES (%s, %s)",
                   (card, cardvalues[countx]))
     DBconn.commit()
     await ctx.send("> **All cards have been added into the table.**",
                    delete_after=40)
Ejemplo n.º 20
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()
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
 async def paste_all_links(ctx):
     # put to 1 if you already have links that can be used
     try:
         self.create_links_number += 1
         number = self.create_links_number
         # if number >= latest post
         c.execute("SELECT PostID FROM currency.DCPost")
         if number >= fetch_one():
             paste_all_links.cancel()
         else:
             my_url = 'https://dreamcatcher.candlemystar.com/post/{}'.format(number)
             async with aiohttp.ClientSession() as session:
                 async with session.get('{}'.format(my_url)) as r:
                     if r.status == 200:
                             page_html = await r.text()
                             page_soup = soup(page_html, "html.parser")
                             username = (page_soup.find("div", {"class": "card-name"})).text
                             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]
                                 member_name = ""
                                 if username == Gahyeon:
                                     member_name = "Gahyeon"
                                 if username == Siyeon:
                                     member_name = "Siyeon"
                                 if username == Yoohyeon:
                                     member_name = "Yoohyeon"
                                 if username == JiU:
                                     member_name = "JIU"
                                 if username == SuA:
                                     member_name = "SUA"
                                 if username == DC:
                                     member_name = "DC"
                                 if username == Dami:
                                     member_name = "Dami"
                                 if username == Handong:
                                     member_name = "Handong"
                                 image_url = (page_soup.findAll("div", {"class": "imgSize width"}))
                                 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}'
                                     try:
                                         c.execute("INSERT INTO currency.DCHDLinks VALUES (%s,%s,%s)", (HD_Link, member_name, number))
                                     except Exception as e:
                                         log.console(e)
                                         pass
                                     DBconn.commit()
                                     log.console(f"DC Link posted on DB for post {number}")
                             else:
                                 log.console("LINK Passing Post from POST #{}".format(number))
                     elif r.status == 304:
                         log.console("> **Access Denied - {}**".format(number))
                     elif r.status == 404:
                         log.console("LINK Error 404. {} was not Found.".format(number))
                         pass
                     else:
                         log.console("LINK Other Error")
     except:
         pass
Ejemplo n.º 23
0
 async def blackjack(self, ctx, *, amount=0):
     """Start a game of BlackJack [Format: %blackjack (amount)] [Aliases: bj]"""
     if amount >= 0:
         try:
             game_type = 'blackjack'
             player_1 = ctx.author.id
             c.execute(
                 "SELECT count(*) FROM currency.Games WHERE Player1 = %s or Player2 = %s",
                 (player_1, player_1))
             counter = fetch_one()
             if counter == 1:
                 embed_message = "**You are already in a pending/active game. Please type %endgame to end your current game.**"
                 embed = discord.Embed(title="Error",
                                       description=embed_message,
                                       color=0xff00f6)
                 await ctx.send(embed=embed, delete_after=40)
             if counter == 0:
                 player_2 = 0
                 player1_bid = amount
                 player2_bid = 0
                 c.execute(
                     "SELECT count(UserID) FROM currency.Currency WHERE USERID = %s",
                     (player_1, ))
                 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_1, ))
                     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(
                             "INSERT INTO currency.Games VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                             (player_1, player_2, player1_bid, player2_bid,
                              0, 0, game_type, 11))
                         DBconn.commit()
                         c.execute(
                             "SELECT GameID FROM currency.Games WHERE Player1 = %s",
                             (player_1, ))
                         game_id = fetch_one()
                         await ctx.send(
                             "> **There are currently 1/2 members signed up for BlackJack. To join the game, please type %joingame {} (bid)**"
                             .format(game_id))
                 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(
                 "> **You are already in a pending/active game. Please type %endgame to end your current game.**",
                 delete_after=40)
     elif amount < 0:
         await ctx.send("> **You cannot bet a negative number**")
Ejemplo n.º 24
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)
Ejemplo n.º 25
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**")
Ejemplo n.º 26
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
Ejemplo n.º 27
0
            async def new_task():
                self.count += 1
                # log.console (game)
                c.execute("SELECT Stand FROM currency.Games WHERE GameID = %s",
                          (game_id, ))
                stand = str(fetch_one())
                if stand == '22':
                    c.execute(
                        "SELECT Score1 FROM currency.Games WHERE GameID = %s",
                        (game_id, ))
                    score_1 = fetch_one()
                    c.execute(
                        "SELECT Score2 FROM currency.Games WHERE GameID = %s",
                        (game_id, ))
                    score_2 = fetch_one()
                    c.execute(
                        "SELECT Bid1 FROM currency.Games WHERE GameID = %s",
                        (game_id, ))
                    bid_1 = fetch_one()
                    c.execute(
                        "SELECT Bid2 FROM currency.Games WHERE GameID = %s",
                        (game_id, ))
                    bid_2 = fetch_one()
                    bid_sum = bid_1 + bid_2
                    c.execute("DELETE FROM currency.Games WHERE GameID = %s",
                              (game_id, ))
                    c.execute(
                        "DELETE FROM currency.BlackJack WHERE GameID = %s",
                        (game_id, ))
                    if score_1 > 21 and score_2 > 21:
                        if score_1 == score_2:
                            await ctx.send(
                                "> **You have both tied with a score of {}! No prizes were given.**"
                                .format(score_1),
                                delete_after=40)
                        result_1 = score_1 - 21
                        result_2 = score_2 - 21
                        if result_1 < result_2:
                            # player 1 wins
                            # add money
                            c.execute(
                                "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                (player_1, ))
                            current_val = int(fetch_one())
                            total_amount = bid_2 + current_val
                            c.execute(
                                "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                (total_amount, player_1))
                            # subtract money
                            c.execute(
                                "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                (player_2, ))
                            current_val = int(fetch_one())
                            total_amount = current_val - bid_2
                            c.execute(
                                "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                (total_amount, player_2))
                            await ctx.send(
                                "> **<@{}> has won {:,} Dollars with {} points against <@{}> with {} points in BlackJack.**"
                                .format(player_1, bid_sum, score_1, player_2,
                                        score_2),
                                delete_after=40)

                        if result_2 < result_1:
                            # player 2 wins
                            # add money
                            c.execute(
                                "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                (player_2, ))
                            current_val = fetch_one()
                            total_amount = bid_1 + current_val
                            c.execute(
                                "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                (total_amount, player_2))
                            # subtract money
                            c.execute(
                                "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                (player_1, ))
                            current_val = int(fetch_one())
                            total_amount = current_val - bid_1
                            c.execute(
                                "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                (total_amount, player_1))
                            await ctx.send(
                                "> **<@{}> has won {:,} Dollars with {} points against <@{}> with {} points in BlackJack.**"
                                .format(player_2, bid_sum, score_2, player_1,
                                        score_1),
                                delete_after=40)
                    if score_1 < 21 and score_2 < 21:
                        if score_1 == score_2:
                            await ctx.send(
                                "> **You have both tied with a score of {}! No prizes were given.**"
                                .format(score_1),
                                delete_after=40)
                        if score_1 > score_2:
                            # player 1 wins
                            # add money
                            c.execute(
                                "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                (player_1, ))
                            current_val = int(fetch_one())
                            total_amount = bid_2 + current_val
                            c.execute(
                                "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                (total_amount, player_1))
                            # subtract money
                            c.execute(
                                "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                (player_2, ))
                            current_val = int(fetch_one())
                            total_amount = current_val - bid_2
                            c.execute(
                                "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                (total_amount, player_2))
                            await ctx.send(
                                "> **<@{}> has won {:,} Dollars with {} points against <@{}> with {} points in BlackJack.**"
                                .format(player_1, bid_sum, score_1, player_2,
                                        score_2),
                                delete_after=40)
                        if score_2 > score_1:
                            # player 2 wins
                            # add money
                            c.execute(
                                "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                (player_2, ))
                            current_val = int(fetch_one())
                            total_amount = bid_1 + current_val
                            c.execute(
                                "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                (f'{total_amount}', player_2))
                            # subtract money
                            c.execute(
                                "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                (player_1, ))
                            current_val = int(fetch_one())
                            total_amount = current_val - bid_1
                            c.execute(
                                "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                (f'{total_amount}', player_1))
                            await ctx.send(
                                "> **<@{}> has won {:,} Dollars with {} points against <@{}> with {} points in BlackJack.**"
                                .format(player_2, bid_sum, score_2, player_1,
                                        score_1),
                                delete_after=40)
                    if score_1 == 21 or score_2 == 21:
                        if score_1 == score_2:
                            await ctx.send(
                                "> **You have both achieved BlackJack as a tie! No prizes were given.**"
                                .format(score_1),
                                delete_after=40)
                        if score_1 != score_2:
                            if score_1 == 21:
                                # player1 wins
                                # add money
                                c.execute(
                                    "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                    (player_1, ))
                                current_val = int(fetch_one())
                                total_amount = bid_2 + current_val
                                c.execute(
                                    "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                    (f'{total_amount}', player_1))
                                # subtract money
                                c.execute(
                                    "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                    (player_2, ))
                                current_val = int(fetch_one())
                                total_amount = current_val - bid_2
                                c.execute(
                                    "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                    (f'{total_amount}', player_2))
                                await ctx.send(
                                    "> **<@{}> has won {:,} Dollars with {} points against <@{}> with {} points in BlackJack.**"
                                    .format(player_1, bid_sum, score_1,
                                            player_2, score_2),
                                    delete_after=40)
                            if score_2 == 21:
                                # player2 wins
                                # add money
                                c.execute(
                                    "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                    (player_2, ))
                                current_val = int(fetch_one())
                                total_amount = bid_1 + current_val
                                c.execute(
                                    "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                    (f'{total_amount}', player_2))
                                # subtract money
                                c.execute(
                                    "SELECT Money FROM currency.Currency WHERE UserID = %s",
                                    (player_1, ))
                                current_val = int(fetch_one())
                                total_amount = current_val - bid_1
                                c.execute(
                                    "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                                    (f'{total_amount}', player_1))
                                await ctx.send(
                                    "> **<@{}> has won {:,} Dollars with {} points against <@{}> with {} points in BlackJack.**"
                                    .format(player_2, bid_sum, score_2,
                                            player_1, score_1),
                                    delete_after=40)
                    if score_1 < 21 and score_2 > 21:
                        # player1 wins
                        # add money
                        c.execute(
                            "SELECT Money FROM currency.Currency WHERE UserID = %s",
                            (player_1, ))
                        current_val = int(fetch_one())
                        total_amount = bid_2 + current_val
                        c.execute(
                            "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                            (f'{total_amount}', player_1))
                        # subtract money
                        c.execute(
                            "SELECT Money FROM currency.Currency WHERE UserID = %s",
                            (player_2, ))
                        current_val = int(fetch_one())
                        total_amount = current_val - bid_2
                        c.execute(
                            "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                            (f'{total_amount}', player_2))
                        await ctx.send(
                            "> **<@{}> has won {:,} Dollars with {} points against <@{}> with {} points in BlackJack.**"
                            .format(player_1, bid_sum, score_1, player_2,
                                    score_2),
                            delete_after=40)
                    if score_1 > 21 and score_2 < 21:
                        # player2 wins
                        # add money
                        c.execute(
                            "SELECT Money FROM currency.Currency WHERE UserID = %s",
                            (player_2, ))
                        current_val = int(fetch_one())
                        total_amount = bid_1 + current_val
                        c.execute(
                            "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                            (f'{total_amount}', player_2))
                        # subtract money
                        c.execute(
                            "SELECT Money FROM currency.Currency WHERE UserID = %s",
                            (player_1, ))
                        current_val = int(fetch_one())
                        total_amount = current_val - bid_1
                        c.execute(
                            "UPDATE currency.Currency SET Money = %s WHERE UserID = %s",
                            (f'{total_amount}', player_1))
                        await ctx.send(
                            "> **<@{}> has won {:,} Dollars with {} points against <@{}> with {} points in BlackJack.**"
                            .format(player_2, bid_sum, score_2, player_1,
                                    score_1),
                            delete_after=40)
                    DBconn.commit()
                    self.tasks.remove(self.task_list)
                    self.count = 0
                    new_task.stop()
                if self.count == 60:
                    await ctx.send(
                        "> **Game {} has been deleted due to it's 5 minute limit.**"
                        .format(game_id))
                    # await ctx.send("sending {}".format(self.task_list))
                    c.execute("DELETE FROM currency.Games WHERE GameID = %s",
                              (game_id, ))
                    c.execute(
                        "DELETE FROM currency.BlackJack WHERE GameID = %s",
                        (game_id, ))
                    DBconn.commit()
                    self.tasks.remove(self.task_list)
                    self.count = 0
                    new_task.stop()
Ejemplo n.º 28
0
 async def addchannel(self,
                      ctx,
                      drive_folder_id,
                      name="NULL",
                      owner_present=0):
     """REQUIRES BOT OWNER PRESENCE -- Make the current channel start archiving images to google drive [Format: %addchannel <drive folder id> <optional - name>]"""
     try:
         if owner_present == 0:
             await ctx.send(
                 f"> **In order to start archiving your channels, you must talk to the bot owner <@{self.bot_owner_id}>**"
             )
         if owner_present == 1:
             await ctx.send("> **Awaiting confirmation**")
             if await self.on_message(ctx, 1):
                 c.execute(
                     "SELECT COUNT(*) FROM archive.ChannelList WHERE DriveID = %s",
                     (drive_folder_id, ))
                 checker = fetch_one()
                 if checker == 0:
                     c.execute(
                         "SELECT COUNT(*) FROM archive.ChannelList WHERE ChannelID = %s",
                         (ctx.channel.id, ))
                     count = fetch_one()
                     if count == 0:
                         url = f"https://drive.google.com/drive/folders/{drive_folder_id}"
                         async with aiohttp.ClientSession() as session:
                             async with session.get(url) as r:
                                 if r.status == 200:
                                     c.execute(
                                         "INSERT INTO archive.ChannelList VALUES(%s,%s,%s,%s)",
                                         (ctx.channel.id, ctx.guild.id,
                                          drive_folder_id, name))
                                     DBconn.commit()
                                     await ctx.send(
                                         f"> **This channel is now being archived under {url}**"
                                     )
                                     pass
                                 elif r.status == 404:
                                     await ctx.send(
                                         f"> **{url} does not exist.**")
                                 elif r.status == 403:
                                     await ctx.send(
                                         f"> **I do not have access to {url}.**"
                                     )
                                 else:
                                     await ctx.send(
                                         f"> **Something went wrong with {url}"
                                     )
                     else:
                         await ctx.send(
                             "> **This channel is already being archived**")
                 else:
                     url = f"https://drive.google.com/drive/folders/{drive_folder_id}"
                     await ctx.send(f"> **{url} is already being used.**")
             else:
                 await ctx.send(
                     "> **The bot owner did not confirm in time.**")
     except Exception as e:
         log.console(e)
         await ctx.send("> **There was an error.**")
     pass