Пример #1
0
 async def checkout(self, ctx, branch: str = "master"):
     """Checks out the requested branch.
     If no branch name is provided will checkout the master branch"""
     pag = Paginator(self.bot, max_line_length=44, max_lines=30, embed=True)
     branches_str = await asyncio.wait_for(
         self.bot.loop.create_task(run_command(f"git branch -a")), 120
     )
     existing_branches = [
         b.strip().split("/")[-1]
         for b in branches_str.replace("*", "").split("\n")[:-1]
     ]
     if branch not in existing_branches:
         pag.add(f"There is no existing branch named {branch}.")
         pag.set_embed_meta(
             title="Git Checkout",
             color=self.bot.error_color,
             thumbnail=f"{ctx.guild.me.avatar_url}",
         )
     else:
         pag.set_embed_meta(
             title="Git Checkout",
             color=self.bot.embed_color,
             thumbnail=f"{ctx.guild.me.avatar_url}",
         )
         result = await asyncio.wait_for(
             self.bot.loop.create_task(run_command(f"git checkout -f {branch}")), 120
         )
         pag.add(result)
     book = Book(pag, (None, ctx.channel, self.bot, ctx.message))
     await book.create_book()
Пример #2
0
    async def haskell_compiler(self, ctx, *, body: str = None):
        if ctx.author.id != self.bot.owner_id:
            return

        if body is None:
            await ctx.send('Nothing to do.')
            return

        async with ctx.typing():
            msg = await ctx.send('Warming up GHC... Please wait.')
            try:
                body = self.cleanup_code(body)
                file_name = f'haskell_{datetime.utcnow().strftime("%Y%m%dT%H%M%S%f")}'
                with open(f'{file_name}.hs', 'w') as f:
                    f.write(body)
                pag = Paginator(self.bot)
                compile_start = time.time()
                pag.add(await asyncio.wait_for(self.bot.loop.create_task(
                    run_command(f'ghc -o {file_name} {file_name}.hs')),
                                               timeout=60))
                compile_end = time.time()
                compile_real = compile_end - compile_start
                book = Book(pag, (msg, ctx.channel, ctx.bot, ctx.message))
                await book.create_book()
                pag = Paginator(self.bot)
                if file_name in os.listdir():
                    run_start = time.time()
                    pag.add(await asyncio.wait_for(self.bot.loop.create_task(
                        run_command(f'./{file_name}')),
                                                   timeout=600))
                    run_end = time.time()
                    run_real = run_end - run_start
                    total_real = run_real + compile_real
                    pag.add(f'\n\nCompile took {compile_real:.2f} seconds')
                    pag.add(f'Total Time {total_real:.2f} seconds')
                    book = Book(pag, (None, ctx.channel, ctx.bot, ctx.message))
                    await msg.delete()
                    await book.create_book()
                os.remove(file_name)
                os.remove(f'{file_name}.hs')
                os.remove(f'{file_name}.o')
                os.remove(f'{file_name}.hi')
            except asyncio.TimeoutError:
                await msg.delete()
                await ctx.send(f"Command did not complete in the time allowed."
                               )
                await ctx.message.add_reaction('❌')
            except FileNotFoundError as e:
                repl_log.warning(e)
Пример #3
0
 async def git(self, ctx):
     """Shows my Git link"""
     branch = (
         await asyncio.wait_for(
             self.bot.loop.create_task(
                 run_command(
                     "git rev-parse --symbolic-full-name " "--abbrev-ref HEAD"
                 )
             ),
             120,
         )
     ).split("\n")[0]
     url = f"{self.bot.git_url}/tree/{branch}"
     em = discord.Embed(
         title=f"Here is where you can find my code",
         url=url,
         color=self.bot.embed_color,
     )
     if branch == "master":
         em.description = (
             "I am Geeksbot. You can find my code here:\n" f"{self.bot.git_url}"
         )
     else:
         em.description = (
             f"I am the {branch} branch of Geeksbot. "
             f"You can find the master branch here:\n"
             f"{self.bot.git_url}/tree/master"
         )
     em.set_thumbnail(url=f"{ctx.guild.me.avatar_url}")
     await ctx.send(embed=em)
Пример #4
0
 async def pull(self, ctx):
     """Pulls updates from GitHub rebasing branch."""
     pag = Paginator(self.bot, max_line_length=100, embed=True)
     pag.set_embed_meta(
         title="Git Pull",
         color=self.bot.embed_color,
         thumbnail=f"{ctx.guild.me.avatar_url}",
     )
     pag.add(
         "\uFFF6"
         + await asyncio.wait_for(
             self.bot.loop.create_task(run_command("git fetch --all")), 120
         )
     )
     pag.add("\uFFF7\n\uFFF8")
     pag.add(
         await asyncio.wait_for(
             self.bot.loop.create_task(
                 run_command(
                     "git reset --hard "
                     "origin/$(git "
                     "rev-parse --symbolic-full-name"
                     " --abbrev-ref HEAD)"
                 )
             ),
             120,
         )
     )
     pag.add("\uFFF7\n\uFFF8")
     pag.add(
         await asyncio.wait_for(
             self.bot.loop.create_task(
                 run_command("git show --stat | " 'sed "s/.*@.*[.].*/ /g"')
             ),
             10,
         )
     )
     book = Book(pag, (None, ctx.channel, self.bot, ctx.message))
     await book.create_book()
Пример #5
0
 async def status(self, ctx):
     """Gets status of current branch."""
     pag = Paginator(self.bot, max_line_length=44, max_lines=30, embed=True)
     pag.set_embed_meta(
         title="Git Status",
         color=self.bot.embed_color,
         thumbnail=f"{ctx.guild.me.avatar_url}",
     )
     result = await asyncio.wait_for(
         self.bot.loop.create_task(run_command("git status")), 120
     )
     pag.add(result)
     book = Book(pag, (None, ctx.channel, self.bot, ctx.message))
     await book.create_book()
Пример #6
0
 async def os(self, ctx, *, body: str):
     if ctx.author.id != self.bot.owner_id:
         return
     try:
         body = self.cleanup_code(body)
         pag = Paginator(self.bot)
         pag.add(await asyncio.wait_for(
             self.bot.loop.create_task(run_command(body)), 120))
         book = Book(pag, (None, ctx.channel, ctx.bot, ctx.message))
         await book.create_book()
         await ctx.message.add_reaction('✅')
     except asyncio.TimeoutError:
         await ctx.send(f"Command did not complete in the time allowed.")
         await ctx.message.add_reaction('❌')