示例#1
0
 async def create(self, ctx, *args):
     """
     Tạo (nhiều) tag mới, có thể có unicode, các tag cách nhau bởi dấu `;`
     Ví dụ ;create Quy Hoạch Động; Segment tree
     """
     tags = list(filter(lambda x: len(x) > 0, args))
     error_msg = ""
     added_msg = ""
     for tag in tags:
         tag = TaggingDb.normalize_tag(tag)
         similar = TaggingDb.TaggingDb.get_similar_tag(tag)
         if len(similar) > 0:
             if similar[0][0] >= _LCS_THRESHOLD_:
                 error_msg += '`{}` giống `{}`\n'.format(tag, similar[0][1])
                 continue
         added_msg += tag + '\n'
         await self._create(None, tag)
     if len(error_msg) > 0:
         embed = discord_common.embed_alert(error_msg.strip())
         await ctx.author.send(
             'Các tag chưa được thêm vì giống trong database, dùng _create để force create:',
             embed=embed)
     if len(added_msg) > 0:
         embed = discord_common.embed_success(added_msg)
         await ctx.author.send('Các tag đã được thêm:', embed=embed)
示例#2
0
 async def modify(self, ctx, old_tag, new_tag):
     old_tag = TaggingDb.normalize_tag(old_tag)
     new_tag = TaggingDb.normalize_tag(new_tag)
     s = TaggingDb.TaggingDb.rename(old_tag, new_tag)
     if s is not None:
         embed = discord_common.embed_alert(s)
         await ctx.author.send(embed=embed)
         return
     # update suggestion
     _LV1_TAGS = json.load(
         open('database/detailed_suggestions.json', encoding='utf-8'))
     for x in _LV1_TAGS:
         for i, tag in enumerate(_LV1_TAGS[x]['codes']):
             if tag == old_tag:
                 _LV1_TAGS[x]['codes'][i] = new_tag
     json.dump(
         _LV1_TAGS,
         open('database/detailed_suggestions.json', 'w', encoding='utf-8'))
     await ctx.author.send(f'Đã đổi tên tag {old_tag} sang {new_tag}')
示例#3
0
 async def suggest(self, ctx, lv1_tag, tag):
     tag = TaggingDb.normalize_tag(tag)
     lv1_tag = TaggingDb.normalize_tag(lv1_tag)
     _LV1_TAGS = json.load(
         open('database/detailed_suggestions.json', encoding='utf-8'))
     if lv1_tag not in _LV1_TAGS:
         msg = [x for x in _LV1_TAGS]
         embed = discord_common.embed_alert(
             f"Không thấy suggestion {lv1_tag}.\n"
             f"Các lv1 tag hiện có: {', '.join([x for x in _LV1_TAGS])}")
         await ctx.author.send(embed=embed)
         return
     _LV1_TAGS[lv1_tag]['codes'].append(tag)
     json.dump(
         _LV1_TAGS,
         open('database/detailed_suggestions.json', 'w', encoding='utf-8'))
     await ctx.author.send(
         f"Đã thêm. Các tag có trong `{_LV1_TAGS[lv1_tag]['name']}`:\n{_LV1_TAGS[lv1_tag]['codes']}"
     )
示例#4
0
 async def _create(self, ctx, *args):
     """
     Force tạo tag mới, chỉ được tạo duy nhất 1
     Ví dụ ;_create Quy Hoạch Động bao lồi cực mạnh
     """
     tags = list(filter(lambda x: len(x) > 0, args))
     for tag in tags:
         tag = TaggingDb.normalize_tag(tag)
         TaggingDb.TaggingDb.add_tag(tag)
         if ctx is not None:
             await ctx.author.send('Tạo tag `{}` thành công'.format(tag))
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    async def info(self, ctx, tag):
        """
        Lấy danh sách các bài có tag cho trước
        Ví dụ ;info dp-tree
        """
        tag = TaggingDb.normalize_tag(tag)
        # ----------------------------
        # get tag
        real_tag = await helper.tag.get_similar_tag(ctx, tag)
        if real_tag is None:
            return
        await ctx.send('Tìm thấy tag `{}` giống với `{}`.'.format(
            real_tag, tag))

        problems = TaggingDb.TaggingDb.get_tagged(real_tag)
        if len(problems) == 0:
            await ctx.send('Chưa có bài nào thuộc tag `{}`'.format(real_tag))
            return
        msg = ""
        for p in problems:
            link = short_link_to_msg(p[0])
            msg += f"[{p[0]}]({link})\n"
        embed = discord.Embed(description=msg.strip())
        await ctx.send('Các bài thuộc tag `{}`'.format(real_tag), embed=embed)