コード例 #1
0
ファイル: Tag.py プロジェクト: leduythuccs/Tagging-bot
    async def done(self, ctx):
        """
        Hoàn thành bài tập đang làm
        Ví dụ ;done
        sẽ hoàn thành việc tag bài hiện tại và được lấy bài mới
        """
        current_problem = codeforces_api.get_current_problem(ctx.author.id)
        if current_problem is None:
            await ctx.author.send(
                f"{ctx.author.mention} chưa được phân công bài nào <:sadness:662197924918329365>,"
                "hãy dùng lệnh `;get` để được phân công bài.")
            return
        embed = problem_to_embed(current_problem,
                                 ctx.author.id,
                                 full_information=True)

        is_tagged = TaggingDb.TaggingDb.is_tagged(
            current_problem['short_link'], ctx.author.id)
        # is_commented = TaggingDb.TaggingDb.check_exists(
        #     'commented', 'problem', current_problem['short_link'])
        if not is_tagged:
            await ctx.author.send(
                "Bạn ơi bài này chưa đc tag ư ư, nếu bạn muốn bỏ qua thì `skip` nha :heart:, các thông tin:",
                embed=embed)
            return
        await self.thanks_channel.send(
            f"Đội ơn bạn {ctx.author.mention} <:orz:661153248186597386> đã làm xong bài:",
            embed=embed)
        TaggingDb.TaggingDb.done(ctx.author.id, current_problem['short_link'])
        submission_link = get_submission_link(current_problem)
        TaggingDb.TaggingDb.add_submission(current_problem['short_link'],
                                           submission_link, ctx.author.id)
        codeforces_api.set_current_problem(ctx.author.id, None)
        await self.get(ctx)
コード例 #2
0
ファイル: Tag.py プロジェクト: leduythuccs/Tagging-bot
    async def skip(self, ctx, *args):
        """
        Bỏ quả bài tập đang làm
        Ví dụ ;skip
        sẽ hoàn thành việc tag bài hiện tại và được lấy bài mới
        """
        current_problem = codeforces_api.get_current_problem(ctx.author.id)
        if current_problem is None:
            await ctx.author.send(
                f"{ctx.author.mention} chưa được phân công bài nào <:sadness:662197924918329365>,"
                "hãy dùng lệnh `;get` để được phân công bài.")
            return
        embed = problem_to_embed(current_problem, ctx.author.id)

        is_tagged = TaggingDb.TaggingDb.is_tagged(
            current_problem['short_link'], ctx.author.id)
        # is_commented = TaggingDb.TaggingDb.check_exists(
        #     'commented', 'problem', current_problem)
        if is_tagged:
            await ctx.author.send(
                "Bạn ơi bài này đã được tag nên không `skip` được nha,"
                "hãy dùng `done` <:aquanice:692418002007883836>, các thông tin:",
                embed=embed)
            return
        await ctx.author.send("Đã bỏ qua bài tập:", embed=embed)
        codeforces_api.set_current_problem(ctx.author.id, None)
        await self.get(ctx)
コード例 #3
0
ファイル: Tag.py プロジェクト: leduythuccs/Tagging-bot
 async def pick(self, ctx, link):
     """
         Tự chọn một bài tập để tag, yêu cầu bài này phải AC trước đó rồi
         ;pick 1339B
         ;pick https://codeforces.com/problemset/problem/1339/B
         ;pick https://codeforces.com/contest/1339/problem/B
     """
     handle = TaggingDb.TaggingDb.get_handle(ctx.author.id)
     if handle is None:
         await ctx.author.send(
             f"Không tìm được codeforces handle của {ctx.author.mention} <:sadness:662197924918329365>."
             "Hãy dùng lệnh `identify` trước")
         return
     short_link = parser.link_parse(link)
     if short_link is None:
         await ctx.author.send(
             f"Format link không đúng, vui lòng dùng 1 trong 3 format sau:\n"
             ";pick 1339B\n"
             ";pick https://codeforces.com/problemset/problem/1339/B\n"
             ";pick https://codeforces.com/contest/1339/problem/B\n")
         return
     problem = await codeforces_api.pick(handle, ctx.author.id, short_link)
     if problem == codeforces_api._IS_TAGGED:
         await ctx.author.send(f"Bài đã được tag")
         return
     if problem == codeforces_api._NOT_FOUND:
         await ctx.author.send(
             f"Không tìm được bài {short_link}, khả năng là bạn chưa AC" +
             "nếu đã AC vui lòng tag @Cá Nóc Cắn Cáp để hỗ trợ")
         return
     if problem == codeforces_api._RATING_TOO_LOW:
         await ctx.author.send(
             f"Không được chọn bài có rating bé hơn {codeforces_api._LIM_RATING}"
         )
         return
     current_problem = codeforces_api.get_current_problem(ctx.author.id)
     if current_problem is not None:
         embed = problem_to_embed(current_problem,
                                  ctx.author.id,
                                  full_information=True)
         is_tagged = TaggingDb.TaggingDb.is_tagged(
             current_problem['short_link'], ctx.author.id)
         if is_tagged:
             await self.thanks_channel.send(
                 f"Đội ơn bạn {ctx.author.mention} <:orz:661153248186597386> đã làm xong bài:",
                 embed=embed)
             TaggingDb.TaggingDb.done(ctx.author.id,
                                      current_problem['short_link'])
             submission_link = get_submission_link(current_problem)
             TaggingDb.TaggingDb.add_submission(
                 current_problem['short_link'], submission_link,
                 ctx.author.id)
             codeforces_api.set_current_problem(ctx.author.id, None)
         else:
             await ctx.author.send("Đã bỏ qua bài tập:", embed=embed)
             codeforces_api.set_current_problem(ctx.author.id,
                                                None,
                                                skip=False)
     # -----------------------------------------------------------
     await handle_new_problem(ctx, problem)
コード例 #4
0
ファイル: Tag.py プロジェクト: leduythuccs/Tagging-bot
    async def add(self, ctx, *args):
        """
        Thêm tag vào bài, lưu ý các tag cần cách nhau bởi space. comment cần được đặt vào giữa 2 dấu \"\".
        Ví dụ: `;add dp-tree bitset dsu-general `\n
        Hoặc: `;add dp-tree \"bài này tuy tag dp-tree nhưng có thể làm thuật toán tham lam tốt hơn\"` (comment cần có ít nhất 3 từ)
        """
        current_problem = codeforces_api.get_current_problem(ctx.author.id)
        if current_problem is None:
            await ctx.author.send(
                f"{ctx.author.mention} chưa được phân công bài nào <:sadness:662197924918329365>,"
                +
                "hãy dùng lệnh `;get` để được phân công bài <:dad:661181642802724894>."
            )
            return
        problem_short_link = current_problem['short_link']
        # parse arg
        params = parser.tag_parse(args)
        if isinstance(params, str):
            embed = discord_common.embed_alert(params)
            await ctx.author.send(embed=embed)
            return
        tags, comment = params
        msg = ""
        any_error = False
        for tag in tags:
            tag = TaggingDb.normalize_tag(tag)
            # get tag
            real_tag = await helper.tag.get_similar_tag(ctx, tag)
            if real_tag is None:
                any_error = True
                continue

            TaggingDb.TaggingDb.tagging(problem_short_link, real_tag,
                                        ctx.author.id)

            msg += '\n-`{}` (giống `{}`).'.format(real_tag, tag)
        if len(msg) != 0:
            await ctx.author.send('Các tag đã tìm thấy:',
                                  embed=discord_common.embed_success(msg))
        if comment == parser._COMMENT_LENGTH_MSG:
            embed = discord_common.embed_alert("Comment cần có ít nhất 3 từ")
            await ctx.send(embed=embed)
        elif len(comment) > 0:
            TaggingDb.TaggingDb.commenting(problem_short_link, comment,
                                           ctx.author.id)
        # --------------------------------------------------------------
        embed = problem_to_embed(current_problem, ctx.author.id)
        if any_error:
            await ctx.author.send('Thông tin hiện tại của bài:', embed=embed)
        else:
            await ctx.author.send(
                'Nếu tag xong rồi bạn có thể dùng `;done` để lấy bài tập mới.'
                'Thông tin hiện tại của bài:',
                embed=embed)
コード例 #5
0
ファイル: Tag.py プロジェクト: leduythuccs/Tagging-bot
    async def force_pick(self, ctx, link, submission_link):
        """
            Tự chọn một bài tập để tag, không yêu cầu AC nhưng cần chèn link code AC
            ;force_pick 1339B https://codeforces.com/contest/1339/submission/76478988
            ;force_pick https://codeforces.com/problemset/problem/1339/B link_AC
            ;force_pick https://codeforces.com/contest/1339/problem/B link_AC
        """
        handle = TaggingDb.TaggingDb.get_handle(ctx.author.id)
        if handle is None:
            await ctx.author.send(
                f"Không tìm được codeforces handle của {ctx.author.mention} <:sadness:662197924918329365>."
                "Hãy dùng lệnh `identify` trước")
            return
        short_link = parser.link_parse(link)
        if short_link is None:
            await ctx.author.send(
                f"Format link đề không đúng, vui lòng dùng 1 trong 3 format sau:\n"
                "1339B\n"
                "https://codeforces.com/problemset/problem/1339/B\n"
                "https://codeforces.com/contest/1339/problem/B\n")
            return
        problem = await codeforces_api.force_pick(handle, ctx.author.id,
                                                  short_link, submission_link)

        current_problem = codeforces_api.get_current_problem(ctx.author.id)
        if current_problem is not None:
            embed = problem_to_embed(current_problem,
                                     ctx.author.id,
                                     full_information=True)
            is_tagged = TaggingDb.TaggingDb.is_tagged(
                current_problem['short_link'], ctx.author.id)
            if is_tagged:
                await self.thanks_channel.send(
                    f"Đội ơn bạn {ctx.author.mention} <:orz:661153248186597386> đã làm xong bài:",
                    embed=embed)
                TaggingDb.TaggingDb.done(ctx.author.id,
                                         current_problem['short_link'])
                submission_link = get_submission_link(current_problem)
                TaggingDb.TaggingDb.add_submission(
                    current_problem['short_link'], submission_link,
                    ctx.author.id)
                codeforces_api.set_current_problem(ctx.author.id, None)
            else:
                await ctx.author.send("Đã bỏ qua bài tập:", embed=embed)
                codeforces_api.set_current_problem(ctx.author.id,
                                                   None,
                                                   skip=False)
        # -----------------------------------------------------------
        await handle_new_problem(ctx, problem)
コード例 #6
0
ファイル: Tag.py プロジェクト: leduythuccs/Tagging-bot
    async def get(self, ctx):
        handle = TaggingDb.TaggingDb.get_handle(ctx.author.id)
        if handle is None:
            await ctx.author.send(
                f"Không tìm được codeforces handle của {ctx.author.mention} <:sadness:662197924918329365>."
                "Hãy dùng lệnh `identify` trước")
            return
        problem = await codeforces_api.get_problem(handle, ctx.author.id)
        if problem is None:
            await ctx.author.send(
                f"Không tìm được bài nào phù hợp cho {ctx.author.mention} <:sadness:662197924918329365>"
            )
            return

        current_problem = codeforces_api.get_current_problem(ctx.author.id)
        if current_problem is not None:
            # todo done info
            embed = problem_to_embed(current_problem, ctx.author.id)
            await ctx.author.send('Thông tin của bài tập hiện tại',
                                  embed=embed)
            return
        await handle_new_problem(ctx, problem)
コード例 #7
0
ファイル: Tag.py プロジェクト: leduythuccs/Tagging-bot
    async def remove(self, ctx, *args):
        """
        Xóa tag đã add vào bài, param giống add
        Ví dụ ;remove dp-tree bitset
        """
        current_problem = codeforces_api.get_current_problem(ctx.author.id)
        if current_problem is None:
            await ctx.author.send(
                f"{ctx.author.mention} chưa được phân công bài nào <:sadness:662197924918329365>,"
                "hãy dùng lệnh `;get` để được phân công bài.")
            return
        problem_short_link = current_problem['short_link']
        # parse arg
        params = parser.tag_parse(args, True)
        if isinstance(params, str):
            embed = discord_common.embed_alert(params)
            await ctx.author.send(embed=embed)
            return
        tags, comment = params
        msg = ""
        for tag in tags:
            tag = TaggingDb.normalize_tag(tag)
            # get tag
            real_tag = await helper.tag.get_similar_tag(ctx, tag)
            if real_tag is None:
                continue

            TaggingDb.TaggingDb.remove_tag(problem_short_link, real_tag,
                                           ctx.author.id)

            msg += '\n-`{}` (giống `{}`).'.format(real_tag, tag)
        if len(msg) != 0:
            await ctx.author.send('Các tag đã tìm thấy:',
                                  embed=discord_common.embed_success(msg))

        embed = problem_to_embed(current_problem, ctx.author.id)
        await ctx.author.send('Thông tin hiện tại của bài:', embed=embed)