Esempio n. 1
0
    async def createclubs(self, ctx, *, clubs):
        """Multiple clubs"""
        path = 'data/clubs.json'
        dataIOa.create_file_if_doesnt_exist(path, '{}')
        clubs_data = dataIOa.load_json(path)
        clubs = clubs.split()
        for c in clubs:
            c = c.lower()
            if c in clubs_data:
                c = c.replace('@', '@\u200b')
                return await ctx.send(f'💢 `{c}` already exists')

        ret = ""
        for c in clubs:
            c = c.lower()
            clubs_data[c] = {
                'creator': ctx.message.author.id,
                'desc': f"[create clubs command]"
                f"({ctx.message.jump_url})",
                'members': [ctx.message.author.id],
                'pings': 0
            }
            ret += f"✅ {c}\n"
        clbs = '\n'.join([f'`{c.lower()}`' for c in clubs])
        confirm = await dutils.prompt(
            ctx,
            f"This will create the club(s):\n{clbs}".replace('@', '@\u200b'))
        if confirm:
            dataIOa.save_json(path, clubs_data)
            await ctx.send(ret)
        else:
            await ctx.send("Cancelling.")
Esempio n. 2
0
    async def leaveclub(self, ctx, club_name):
        """Leave a club"""
        club_name = club_name.lower()

        path = 'data/clubs.json'
        dataIOa.create_file_if_doesnt_exist(path, '{}')
        clubs_data = dataIOa.load_json(path)
        if club_name in clubs_data:
            club = clubs_data[club_name]
            mems = [
                ctx.guild.get_member(u) for u in club['members']
                if ctx.guild.get_member(u)
            ]
            if ctx.author in mems:
                clubs_data[club_name]['members'].remove(ctx.author.id)
                dataIOa.save_json(path, clubs_data)
                await ctx.send(
                    f"{ctx.author.mention} has left the club {club_name}")
            else:
                return await ctx.send(
                    f"{self.get_emote_if_exists_else(ctx.guild, 'HestiaNo', '💢')} "
                    f"You are not even in this club")
        else:
            suggestion = self.findMostSimilar(club_name, [*clubs_data])
            emote_test = utils.get(ctx.guild.emojis, name="HestiaNo")
            emote = "💢" if not emote_test else str(emote_test)
            await ctx.send(
                f'{emote} No such club found, did you perhaps mean `{suggestion}`'
            )
Esempio n. 3
0
def check_file():
    jdict = {
        "prefix": ">",
        "alias": {
            'alias example': {
                'linux':
                'printf "Hello.\n'
                'This is an alias made using the magic of python."',
                'windows':
                'echo Hello. '
                'This is an alias made using the magic of python.'
            }
        },
        "os": {
            'windows': '{path}>',
            'linux': '{user}@{system}:{path} $ '
        },
        "cos": "default",
        "enabled": True
    }

    if not dataIO.is_valid_json(
            abspath(dirname(argv[0])) +
            '/settings/terminal_settings.json') or 'cc' in dataIO.load_json(
                abspath(dirname(argv[0])) +
                '/settings/terminal_settings.json'):
        print("[Terminal]Creating default settings.json...")
        dataIO.save_json(
            abspath(dirname(argv[0])) + '/settings/terminal_settings.json',
            jdict)
Esempio n. 4
0
    async def _os(self, ctx, os: str = None):
        """Set the prompt type of BetterTerminal to emulate another Operatingsystem.
        these 'emulations' arent 100% accurate on other Operating systems"""

        if os is None:
            formatter = self.bot.help_command
            pages = await formatter.format_help_for(ctx, ctx.command)
            for page in pages:
                await ctx.send(content=None, embed=page)
            if self.cos == 'default':
                await ctx.send('```\nCurrent prompt type: {}[{}] ```\n'
                               ''.format(self.cos,
                                         uname()[0].lower()))
            else:
                await ctx.send('```\nCurrent prompt type: {} ```\n'.format(
                    self.cos))
            return

        if not os.lower() in self.os and os != 'default':
            await ctx.send(
                'Invalid prompt type.\nThe following once are valid:\n\n{}'
                ''.format(", ".join(self.os)))
            return

        os = os.lower()

        self.cos = os
        self.settings['cos'] = os
        dataIO.save_json(
            abspath(dirname(argv[0])) + '/settings/terminal_settings.json',
            self.settings)
        await ctx.send('Changed prompt type to {} '.format(
            self.cos.replace("`", "\\`")))
Esempio n. 5
0
 async def _alias(self, ctx, add_or_remove, alias, text: str = None):
     """Custom aliases for BetterTerminal"""
     if self.cos == "default":
         os = uname()[0].lower()
     else:
         os = self.cos
     if add_or_remove == "add":
         if not text:
             return await ctx.send(
                 f"Error. Missing command to alias. Ex: `{dutils.bot_pfx(ctx.bot, ctx.message)}cmdsettings "
                 f"alias add \"test\" \"cat log.txt\"")
         else:
             self.alias[alias] = {os: text}
     elif add_or_remove in ["remove", "delete", "rm"]:
         if alias not in self.alias:
             return await ctx.send("Error. Specified alias not found.")
         else:
             del self.alias[alias][os]
             if not self.alias[alias]:
                 del self.alias[alias]
     self.settings["alias"] = self.alias
     dataIO.save_json(
         abspath(dirname(argv[0])) + '/settings/terminal_settings.json',
         self.settings)
     if add_or_remove == "add":
         await ctx.send("Successfully added alias.")
     elif add_or_remove in ["remove", "delete", "rm"]:
         await ctx.send("Successfully removed alias.")
Esempio n. 6
0
async def restart(ctx, options: str = ""):
    """Restart the bot and git pull changes.

    Use "v" for verbose,
    Use "u" for update
    Use "vu"/"uv" for both """
    if "u" in options:
        if bot.config['NEW_MAIN_D']:
            os.rename(bot.config['NEW_MAIN_D'], 'main_d3.py')
        if bot.config['NEW_BOT_LOOP']:
            os.rename(bot.config['NEW_BOT_LOOP'], 'bot_loop3.py')
        await ctx.send("Running `git pull`...")
        loop = asyncio.get_event_loop()
        process = subprocess.Popen(["git", "pull"], stdout=subprocess.PIPE)
        output = await loop.run_in_executor(None, process.communicate)
        if "v" in options:
            a = output[0].decode(encoding='utf8', errors='ignore')
            if len(a) > 1900: a = a[:1900] + "\n\n...Content longer than 1900 chars"
            await ctx.send(f"```{a}```")
        else:
            await ctx.send("Git pulled.")
        if bot.config['NEW_MAIN_D']:
            os.rename('main_d3.py', bot.config['NEW_MAIN_D'])
        if bot.config['NEW_BOT_LOOP']:
            os.rename('bot_loop3.py', bot.config['NEW_BOT_LOOP'])
    await ctx.send("Restarting...")
    restarT = {"guild": ctx.guild.id, "channel": ctx.channel.id}
    dataIOa.save_json("restart.json", restarT)
    exit_bot(0)
Esempio n. 7
0
async def globalprefix(ctx, *, new_prefix=""):
    """Check or change the main default prefix

    If you need spaces, do {space_here}
    and it will be replaced with spaces
    ...Or just use spaces (usable if you need the mat the end)"""
    if '@' in new_prefix: return await ctx.send("The character `@` is not allowed in "
                                                "the bot's prefix. Try again.")
    if not new_prefix:
        return await ctx.send(embed=Embed(title='My main prefix is', description=bot.config['BOT_PREFIX']))
    if '{space_here}' in new_prefix:  new_prefix = new_prefix.replace('{space_here}', ' ')
    if new_prefix.strip() == "": return await ctx.send("A prefix can not be only spaces.")
    if bot.config['BOT_PREFIX'] == new_prefix: return await ctx.send(
        "Why are you trying to make the new prefix the same "
        "as the previous one? Oh yeah, if you are trying to make a prefix"
        "with a space at the end, for example `bb command` then do: "
        "`.prefix bb{space_here}`")
    bot.config['BOT_PREFIX'] = new_prefix
    conf_copy = bot.config.copy()
    conf_copy["BOT_DM_LOG"]["CAN_SEND"] = 0
    conf_copy["BOT_DM_LOG"]["HOOK"] = 0
    conf_copy['BOT_DEFAULT_EMBED_COLOR'] = 0
    dataIOa.save_json("config.json", conf_copy)
    global Prefix
    Prefix = new_prefix
    await ctx.send("Prefix changed.")
Esempio n. 8
0
    async def pingclubs(self, ctx, *, clubs_and_rest_text):
        """Ping multiple clubs, please see detailed usage
        Syntax:
        `[p]ping2 club1 club2 club3; any other content you wish`
        `[p]ping2 club1 club2`
        Example:
        Club Yuri: ['user1', 'user2']
        Club Fate: ['user1', 'user3']
        This command works with the **OR** or **UNION** operator.
        When doing `[p]ping2 yuri fate; cool Eresh x Ishtar pics`
        The bot will ping the users: @user1 @user2 @user3
        """
        clubs = clubs_and_rest_text.rsplit(';', 1)[:1][0].split(' ')
        clubs = [c.lower() for c in clubs]
        clubs = list(set(clubs))
        if len(clubs) < 2:
            return await ctx.send("Need at least 2 clubs for this command")

        all_ok = await self.check_if_clubs_exist(ctx, clubs)

        if all_ok:
            path = 'data/clubs.json'
            dataIOa.create_file_if_doesnt_exist(path, '{}')
            clubs_data = dataIOa.load_json(path)
            mems_all = []
            clubs_all = ""
            for club_name in clubs:
                club = clubs_data[club_name]
                mems = [
                    ctx.guild.get_member(u) for u in club['members']
                    if ctx.guild.get_member(u)
                ]
                clubs_data[club_name]['pings'] += 1
                mems_all = list(set([*mems_all, *mems]))
                clubs_all += club_name + ', '
            dataIOa.save_json(path, clubs_data)

            pings = ['']
            cur_idx = 0
            for m in mems_all:
                pings[cur_idx] += m.mention + ' '
                if len(pings[cur_idx]) + len(clubs_all) > 1900:
                    cur_idx += 1
                    pings.append('')

            for p in pings:
                if p: await ctx.send(f'Clubs: {clubs_all[:-2]} {p}')
Esempio n. 9
0
    async def _prefix(self, ctx, prefix: str = None):
        """Set the prefix for the Terminal"""

        if prefix is None:
            formatter = self.bot.help_command
            pages = await formatter.format_help_for(ctx, ctx.command)
            for page in pages:
                await ctx.send(content=None, embed=page)
            await ctx.send('```\nCurrent prefix: {} ```\n'.format(self.prefix))
            return

        self.prefix = prefix
        self.settings['prefix'] = prefix
        dataIO.save_json(
            abspath(dirname(argv[0])) + '/settings/terminal_settings.json',
            self.settings)

        await ctx.send('Changed prefix to {} '.format(
            self.prefix.replace("`", "\\`")))
Esempio n. 10
0
    async def pingclub(self,
                       ctx,
                       club_name,
                       *,
                       rest="Anything else that you'd like to add"):
        """Ping a club"""
        club_name = club_name.lower()

        path = 'data/clubs.json'
        dataIOa.create_file_if_doesnt_exist(path, '{}')
        clubs_data = dataIOa.load_json(path)
        if club_name in clubs_data:
            club = clubs_data[club_name]
            # creator = ctx.guild.get_member(int(club['creator']))
            mems = [
                ctx.guild.get_member(u) for u in club['members']
                if ctx.guild.get_member(u)
            ]
            if ctx.author not in mems and not ctx.author.guild_permissions.administrator:
                return await ctx.send(
                    f"{self.get_emote_if_exists_else(ctx.guild, 'HestiaNo', '💢')} "
                    f"You can't ping a club you're not a part of")
            pings = ['']
            clubs_data[club_name]['pings'] += 1
            dataIOa.save_json(path, clubs_data)
            cur_idx = 0
            for m in mems:
                pings[cur_idx] += m.mention + ' '
                if len(pings[cur_idx]) + len(club_name) > 1900:
                    cur_idx += 1
                    pings.append('')

            for p in pings:
                if p: await ctx.send(f'Club: {club_name} {p}')

        else:
            suggestion = self.findMostSimilar(club_name, [*clubs_data])
            emote_test = utils.get(ctx.guild.emojis, name="HestiaNo")
            emote = "💢" if not emote_test else str(emote_test)
            await ctx.send(
                f'{emote} No such club found, did you perhaps mean `{suggestion}`'
            )
Esempio n. 11
0
    async def deleteclubs(self, ctx, *, clubs_to_delete):
        """Delete clubs, seperate with a space if deleting many"""
        path = 'data/clubs.json'
        dataIOa.create_file_if_doesnt_exist(path, '{}')
        clubs_data = dataIOa.load_json(path)
        notIn = ""
        wasIn = ""
        for c in clubs_to_delete.split(' '):
            if c in clubs_data:
                del clubs_data[c]
                wasIn += f"{c} "
            else:
                notIn += f"{c} "

        # clbs = '\n'.join([f'`{c.lower()}`' for c in clubs_to_delete])
        confirm = await dutils.prompt(
            ctx, "https://tenor.com/view/are-you-sure"
            "-john-cena-ru-sure-about-dat-gif-14258954")
        if confirm:
            await ctx.send(f"Deleted: {wasIn}\nFailed to delete: {notIn}")
            dataIOa.save_json(path, clubs_data)
        else:
            await ctx.send("Cancelling.")
Esempio n. 12
0
    async def recc(self, event):
        # event.guild_id event.user_id event.message_id event.channel_id
        if event.channel_id == self.verification_channel_id:
            g = self.bot.get_guild(int(event.guild_id))
            ch = g.get_channel(int(event.channel_id))
            msg = await ch.fetch_message(event.message_id)
            if event.user_id == self.bot.config["CLIENT_ID"]:
                return  # in case the bot is adding reactions
            if msg.author.id == self.bot.config["CLIENT_ID"] and str(
                    event.emoji) in ['✅', '❌']:
                await msg.clear_reactions()
                try:
                    split = msg.embeds[0].description.split('\n')
                    club_title = split[0].split(' ')[-1]
                    club_creator = g.get_member(int(split[1].split(' ')[-1]))
                    club_desc = ' '.join(split[2].split(' ')[1:])
                    if str(event.emoji) == '✅':
                        path = 'data/clubs.json'
                        dataIOa.create_file_if_doesnt_exist(path, '{}')
                        clubs_data = dataIOa.load_json(path)
                        clubs_data[club_title] = {
                            'creator': club_creator.id,
                            'desc': club_desc,
                            'members': [club_creator.id],
                            'pings': 0
                        }
                        dataIOa.save_json(path, clubs_data)

                        await club_creator.send(
                            f'The club **{club_title}** has been approved ✅')
                        await ch.send(
                            f'The club **{club_title}** has been '
                            f'approved by {g.get_member(event.user_id)} ✅')
                    if str(event.emoji) == '❌':
                        await club_creator.send(
                            f'The club **{club_title}** has been denied ❌')
                        await ch.send(
                            f'The club **{club_title}** has been '
                            f'denied by {g.get_member(event.user_id)} ❌')
                except:
                    pass
                await msg.add_reaction('🔖')
        if event.channel_id == 795720249462882354:
            if event.user_id == self.bot.config["CLIENT_ID"]:
                return  # in case the bot is adding reactions
            g = self.bot.get_guild(int(event.guild_id))
            ch = g.get_channel(int(event.channel_id))
            msg = await ch.fetch_message(event.message_id)
            dic = {(ll.split(' ')[0]).replace('<a:', '<:'):
                   (' '.join(ll.split(' ')[1:])).strip()
                   for ll in msg.content.split('\n')}
            d = 0
            add = event.event_type == 'REACTION_ADD'
            e = str(event.emoji).replace('<a:', '<:')
            if e in dic:
                club_name = dic[e]
                club_name = club_name.lower()
                path = 'data/clubs.json'
                dataIOa.create_file_if_doesnt_exist(path, '{}')
                clubs_data = dataIOa.load_json(path)
                club = clubs_data[club_name]
                mems = [(g.get_member(u)).id for u in club['members']
                        if g.get_member(u)]
                # rch = g.get_channel(470822975676088350)
                if event.user_id not in mems and add:
                    clubs_data[club_name]['members'].append(event.user_id)
                    dataIOa.save_json(path, clubs_data)
                    await ch.send(
                        f"<@{event.user_id}> has joined the club **{club_name}** ✅",
                        delete_after=5)
                if event.user_id in mems and not add:
                    clubs_data[club_name]['members'].remove(event.user_id)
                    dataIOa.save_json(path, clubs_data)
                    await ch.send(
                        f"<@{event.user_id}> has left the club **{club_name}** ❌",
                        delete_after=5)
Esempio n. 13
0
    async def el_catboxpls(self, ctx, auto=False):
        rets = []
        ret = ""
        to_ret = """
        socket.sendCommand({
            type: "library",
            command: "expandLibrary answer",
            data: {
                annId: [ANNID],
                annSongId: [ANNSONGID],
                url: "[URL]",
                resolution: 0    
            }
        })
                """
        data = dataIOa.load_json('data/_amq/toProcessNoMp3.json')
        dataIOa.save_json('data/_amq/BACKUP_toProcessNoMp3.json', data)
        # print("Saving temporary data, you'll need this later (in case of a crash)"
        #      " in order to make the final output btw.")
        uploaded = dataIOa.load_json('data/_amq/uploaded_name.json')
        uploaded_l = dataIOa.load_json('data/_amq/uploaded_links.json')
        cnt = 0
        while len(data) > 0:
            upl = data.pop()
            if int(upl["annID"]) in self.ignored_ann_ids:
                continue
            loop = asyncio.get_event_loop()
            ll = 'link_7'
            if 'link_4' in upl:
                ll = 'link_4'

            ee = get_valid_filename(upl["songName"])
            out = f'tmp/amq/{upl["annID"]}_{upl["annSongId"]}_{ee}.mp3'

            if not os.path.exists(out) or (os.path.exists(out) and
                                           (out not in uploaded)):
                fil = upl[ll].replace(
                    'files.',
                    'nl.')  # actually just use NL now that it's active
                await ctx.send(f"Creating **{out}** from <{fil}>")
                if os.path.exists(out):
                    os.remove(out)  # we go agane
                # fil = upl[ll]  # better safe than sorry zzzzzzzzzzzzzz
                # panic for no log basically | info
                LOGLEVEL = "panic"
                process = subprocess.Popen([
                    "ffmpeg", "-hide_banner", "-loglevel", LOGLEVEL, "-i", fil,
                    "-b:a", "320k", "-ac", "2", "-map", "a:0", out, "-y"
                ],
                                           stdout=subprocess.PIPE)
                await loop.run_in_executor(None, process.communicate)
                await asyncio.sleep(0.1)
                if not os.path.exists(out):
                    process = subprocess.Popen([
                        "ffmpeg", "-hide_banner", "-loglevel", LOGLEVEL, "-i",
                        fil, "-b:a", "320k", "-ac", "2", "-map", "a:0", out,
                        "-y"
                    ],
                                               stdout=subprocess.PIPE)
                    await loop.run_in_executor(None, process.communicate)
                    await asyncio.sleep(0.1)

            feedback = True
            if out not in uploaded:
                if not await self.is_catbox_alive():
                    await ctx.send("❗❗Catbox ded rn. Continue later..")
                    raise
                await ctx.send(f"Uploading **{out}**")
                ok, link = await self.upload_file_to_catbox(out, ctx)
            else:
                feedback = False
                ok = True
                link = uploaded_l[uploaded.index(out)]
            link = str(link).replace('\n', '').replace(' ', '')
            if not ok:
                await ctx.send("Something went wrong... Details:")
                print(link)
                await dutils.print_hastebin_or_file(ctx, f'```\n{link}```')
                raise

            uploaded.append(out)
            uploaded_l.append(link)
            dataIOa.save_json('data/_amq/uploaded_name.json', uploaded)
            dataIOa.save_json('data/_amq/uploaded_links.json', uploaded_l)
            ret += to_ret.replace('[ANNID]', str(upl["annID"])).replace('[ANNSONGID]', str(upl["annSongId"])). \
                replace('[URL]', str(link)). \
                replace('socket.sendCommand(', '').replace('})', '}')
            if feedback:
                await ctx.send(
                    to_ret.replace('[ANNID]', str(upl["annID"])).replace(
                        '[ANNSONGID]',
                        str(upl["annSongId"])).replace('[URL]', str(link)))
            if cnt < 20:
                ret += ','
                cnt += 1
            else:
                rets.append(ret)
                ret = ""
                cnt = 0
            if len(data) == 0 and ret:
                rets.append(ret)

            # dataIOa.save_json('data/_amq/toProcessNoMp3.json', data)  # NVM: wait why do you keep overwriting this?

        # await ctx.send("""```js
        # socket.sendCommand({
        #    type: "library",
        #    command: "expandLibrary questions"
        # })
        #        ```""")
        LB = "{"
        RB = "}"
        if not auto:
            await ctx.send(f"{ctx.author.mention} **All:**")

        deff = """function _sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }"""
        rr = "{socket.sendCommand(ex[ii]);\nconsole.log(ex[ii]);\nawait _sleep(700);}"
        rett = []
        for r in rets:
            rett.append(
                f'{deff}\n\nvar ex=[{r}]\nasync '
                f'function doIT(){LB}for(let ii=0;ii<ex.length;ii++){LB}{rr}{RB}return ex.length;{RB}'
                f'\nreturn await doIT();')
        if rett:
            await dutils.print_hastebin_or_file(
                ctx, '\n'.join(rett),
                just_file=True)  # for some reason hastebin sux
        return rett
Esempio n. 14
0
    async def el_get_no_mp3(self,
                            ctx,
                            driver,
                            just_last_invoke=False,
                            d_scripts=None):
        driver.get("https://animemusicquiz.com/?forceLogin=True")
        driver.implicitly_wait(10)

        # in case I was logged out
        try:
            driver.implicitly_wait(5)
            try:
                eee = driver.find_element_by_xpath(
                    """/html/body/div[1]/div/a""")
                eee.click()
            except:
                pass
            await asyncio.sleep(2)
            try:
                driver.find_element_by_xpath("""//*[@id="mpPlayButton"]""")
                isOK = True
            except:
                isOK = False
            if isOK:
                raise
            for i in range(5):
                try:
                    driver.get(f"https://animemusicquiz.com/?forceLogin=True")
                    driver.find_element_by_xpath("""//*[@id="mpPlayButton"]""")
                    break
                except:
                    await asyncio.sleep(1)
                    un = driver.find_element_by_xpath(
                        """//*[@id="loginUsername"]""")
                    un.click()
                    un.send_keys(ctx.bot.config['AMQ_USERNAME'])

                    pw = driver.find_element_by_xpath(
                        """//*[@id="loginPassword"]""")
                    pw.click()
                    pw.send_keys(ctx.bot.config['AMQ_PASSWORD'])

                    signIn = driver.find_element_by_xpath(
                        """//*[@id="loginButton"]""")
                    signIn.click()
                    print("Login")
                    await asyncio.sleep(1)
                    bbreak = True
                    try:
                        contLog = driver.find_element_by_xpath(
                            """//*[@id="alreadyOnlineContinueButton"]""")
                        contLog.click()
                        break
                    except:
                        pass
                    try:
                        test = driver.find_element_by_xpath(
                            """//*[@id="mpPlayButton"]""")
                    except:
                        bbreak = False
                    if bbreak:
                        break
        except:
            pass

        if not just_last_invoke:
            driver.implicitly_wait(10)
            await asyncio.sleep(5)
            opt = driver.find_element_by_xpath(
                """//*[@id="optionGlyphIcon"]""")
            opt.click()
            await asyncio.sleep(2)
            sett = driver.find_element_by_xpath(
                """//*[@id="optionsContainer"]/ul/li[3]""")
            sett.click()
            mmm = driver.find_element_by_xpath(
                """//*[@id="settingModal"]/div/div/div[2]/div[2]""")
            mmm.click()
            mn = driver.find_element_by_xpath(
                """//*[@id="malUserNameInput"]""")
            mn.click()
            mn.send_keys(Keys.CONTROL, "a")
            mn.clear()
            mn.send_keys("kikimanox")
            getMal = driver.find_element_by_xpath(
                """//*[@id="malUpdateButton"]""")
            getMal.click()
            await ctx.send("Trying to update MAL")
            driver.implicitly_wait(90)
            succ = driver.find_element_by_xpath("""//*[@id="swal2-title"]""")
            print(succ.text)
            if succ.text == "Update Successful":
                await ctx.send("MAL Updated.")
            else:
                await ctx.send("MAL Update failed.")
                raise
            # kk = driver.find_element_by_xpath("""/html/body/div[4]/div/div[3]/button[1]""")
            # kk.click()
            # cls = driver.find_element_by_xpath("""//*[@id="settingModal"]/div/div/div[1]/div/button""")
            # cls.click()

        # GO TO EXPAND
        driver.get("https://animemusicquiz.com/?forceLogin=True")
        driver.implicitly_wait(30)
        ex = driver.find_element_by_xpath("""//*[@id="mpExpandButton"]""")
        ex.click()
        await asyncio.sleep(3)
        first = driver.find_element_by_xpath(
            """//*[@id="elQuestionList"]/div[4]/div[1]/div[1]""")

        if not just_last_invoke:
            stuff = driver.execute_script(self.gib_code2)
            # print(stuff)
            dataIOa.save_json('data/_amq/toProcessNoMp3.json',
                              json.loads(json.dumps(stuff)))
            await ctx.send("Saved data to parse.")

        if just_last_invoke:
            await ctx.send("Invoking sockets.")

            i = 1
            for scr in d_scripts:
                val = driver.execute_script(scr)
                await ctx.send(f"[{i}/{len(d_scripts)}] Done. ({val} added)")
                i += 1

            try:
                await asyncio.sleep(2)
                opt = driver.find_element_by_xpath(
                    """//*[@id="optionGlyphIcon"]""")
                opt.click()
                await asyncio.sleep(2)
                sett = driver.find_element_by_xpath(
                    """//*[@id="optionsContainer"]/ul/li[3]""")
                sett.click()
                mmm = driver.find_element_by_xpath(
                    """//*[@id="settingModal"]/div/div/div[2]/div[2]""")
                mmm.click()
                mn = driver.find_element_by_xpath(
                    """//*[@id="malUserNameInput"]""")
                mn.click()
                mn.send_keys(Keys.CONTROL, "a")
                mn.clear()
                mn.send_keys("kikimanox2")
                getMal = driver.find_element_by_xpath(
                    """//*[@id="malUpdateButton"]""")
                getMal.click()
                await ctx.send("Trying to update MAL back to kikimanox2")
                driver.implicitly_wait(60)
                succ = driver.find_element_by_xpath(
                    """//*[@id="swal2-title"]""")
                # print(succ.text)
                if succ.text == "Updated Successful":
                    await ctx.send("MAL Updated.")
                else:
                    await ctx.send("MAL Update failed.")
            except:
                await ctx.send(
                    "Something went wrong when updagint MAL list back to kikimanox2"
                )
Esempio n. 15
0
    async def el_crawl(self, ctx, start_from_page: int, _driver=None):
        # if not await dutils.prompt(ctx, "Are you running this locally?"):
        #    return await ctx.send("Cancelled")
        await ctx.send("Starting to crawl")
        options = Options()
        options.headless = True
        options.add_argument('window-size=1920x1080')
        options.binary_location = r"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
        c = r"A:\\Unsorted\\old-desktop-junk\\chromedriver_win32\\chromedriver.exe"
        if not _driver:
            driver = webdriver.Chrome(c, chrome_options=options)
        else:
            driver = _driver
        print('strating...')
        # driver.minimize_window()
        driver.get("https://animemusicquiz.com/?forceLogin=True")
        driver.implicitly_wait(10)
        eee = driver.find_element_by_xpath("""/html/body/div[1]/div/a""")
        eee.click()
        await asyncio.sleep(2)
        driver.implicitly_wait(3)

        for i in range(5):
            try:
                driver.get(f"https://animemusicquiz.com/")
                driver.find_element_by_xpath(
                    """//*[@id="adminPage"]/div/table/tbody"""
                )  # this is wrong btw
                break
            except:
                await asyncio.sleep(1)
                un = driver.find_element_by_xpath(
                    """//*[@id="loginUsername"]""")
                un.click()
                un.send_keys(ctx.bot.config['AMQ_USERNAME'])

                pw = driver.find_element_by_xpath(
                    """//*[@id="loginPassword"]""")
                pw.click()
                pw.send_keys(ctx.bot.config['AMQ_PASSWORD'])

                signIn = driver.find_element_by_xpath(
                    """//*[@id="loginButton"]""")
                signIn.click()
                print("Login")
                await asyncio.sleep(1)
                bbreak = True
                try:
                    contLog = driver.find_element_by_xpath(
                        """//*[@id="alreadyOnlineContinueButton"]""")
                    contLog.click()
                    break
                except:
                    pass
                try:
                    test = driver.find_element_by_xpath(
                        """//*[@id="mpPlayButton"]""")
                except:
                    bbreak = False
                if bbreak:
                    break

        driver.implicitly_wait(10)
        driver.get(
            f"https://animemusicquiz.com/admin/fixIds?known=true&page=1")

        cur_data = dataIOa.load_json('data/_amq/annMal.json')

        lp = 0
        for i in range(start_from_page, 200):
            driver.get(
                f"https://animemusicquiz.com/admin/fixIds?known=true&page={i}")
            print(f"page {i}")
            await asyncio.sleep(0.3)
            lastPage = False
            try:
                driver.find_element_by_xpath(
                    """//*[@id="adminPage"]/div/table/tbody/tr[2]""")
            except:
                lastPage = True
            if lastPage:
                print("Reached last page")
                break
            lp = i
            tbl2 = driver.find_elements_by_xpath(
                """//*[@id="adminPage"]/div/table/tbody/tr[position() > 1]""")
            for t in tbl2:
                mID = t.get_attribute("data-malid")
                aID = t.get_attribute("data-annid")
                # print(f'{aID} {t.text}')
                cur_data[str(aID)] = t.text

        dataIOa.save_json('data/_amq/annMal.json', cur_data)
        await ctx.send(
            f"Done. (Last page that worked was `{lp}` (for `docrawl`))")
        if not _driver:
            driver.close()