Ejemplo n.º 1
0
def nalgang_point():
    userID = request.args.get('id',type=int)
    userGuild =  request.args.get('guild',type=int)
    m = Member(None)
    m.id = userID
    m.guild = userGuild
    return str(m.get_point())
Ejemplo n.º 2
0
Archivo: bot.py Proyecto: 3-24/nalgang
async def register(ctx):
    member = Member(ctx.author)
    if member.exist_db():
        await ctx.channel.send("이미 등록된 사용자입니다.")
    else:
        member.add_db()
        await ctx.channel.send("등록되었습니다.")
Ejemplo n.º 3
0
async def nalgang(ctx, *, arg=""):
    member = Member(ctx.author)
    msg = arg
    if len(msg) > 280: msg = msg[:280]

    present_time = datetime.today()
    if is_day_changed(time_read(), present_time, update_time_delta):
        day_reset()
        time_save(present_time)

    result = member.nalgang(msg)

    if result == None:
        await ctx.channel.send("{:s}님은 이미 날갱되었습니다.".format(member.name))
    else:
        point, combo_point = result
        await ctx.channel.send("{:s}님이 날갱해서 {:d}점을 얻었습니다!".format(
            member.name, point))
        if combo_point != 0:
            await ctx.channel.send("와! {:s}님이 전근으로 {:d}점을 얻었습니다!".format(
                member.name, combo_point))

    attendance_info = get_all_attendance_info()
    description = ""
    for index, info in enumerate(attendance_info):
        name = ctx.guild.get_member(info[0]).display_name
        msg = info[1]
        description += str(index + 1) + ". " + name + ": " + msg + "\n"

    embed = discord.Embed(title="오늘의 날갱",
                          description=markdown_escape(description))
    await ctx.channel.send(embed=embed)
    return
Ejemplo n.º 4
0
async def add(ctx, user: discord.Member, delta: int):
    if not (ctx.author.id in admin_ids): return
    member = Member(user)
    prev_point = member.get_point()
    member.set_point(prev_point + delta)
    await ctx.send(
        f"Successfully added {delta} points to {user.display_name}, now {member.get_point()}"
    )
    return
Ejemplo n.º 5
0
 def testNalgangMonthBonus(self):
     m1 = Member(None)
     m1.id_num = 1
     m1.name = "Alice"
     m1.add_db(combo=29)
     m1.nalgang("")
     self.assertEqual(m1.get_point(),
                      config.point_by_rank[0] + config.month_bonus)
     self.assertEqual(m1.get_combo(), 30)
Ejemplo n.º 6
0
Archivo: test.py Proyecto: 3-24/nalgang
 def testDatabase(self):
     m1 = Member(None)
     m1.id = 1
     m1.name = "Alice"
     m1.guild = 2222
     m1.add_db(point=123456, combo=654321)
     self.assertEqual(m1.get_point(), 123456)
     self.assertEqual(m1.get_combo(), 654321)
Ejemplo n.º 7
0
Archivo: bot.py Proyecto: 3-24/nalgang
async def point(ctx, arg=None):
    if arg == None: user = ctx.author
    else: user = await commands.MemberConverter().convert(ctx, arg)

    member = Member(user)

    if not member.exist_db():
        await ctx.channel.send("등록되지 않은 사용자입니다.")
        return

    await ctx.channel.send("{:s}님의 날갱점수는 {:d}점입니다. {:d}연속 출석 중입니다.".format(
        member.name, member.get_point(), member.get_combo()))
    return
Ejemplo n.º 8
0
async def force_nalgang(ctx):
    if not (ctx.author.id in admin_ids):
        return
    ids = ctx.message.raw_mentions
    for Id in ids:
        member = Member(ctx.guild.get_member(Id))
        result = member.nalgang("강제날갱")

        if result == None:
            await ctx.channel.send("{:s}님은 이미 날갱되었습니다.".format(member.name))
        else:
            point, combo_point = result
            await ctx.channel.send("{:s}님이 날갱해서 {:d}점을 얻었습니다!".format(
                member.name, point))
            if combo_point != 0:
                await ctx.channel.send("와! {:s}님이 전근으로 {:d}점을 얻었습니다!".format(
                    member.name, combo_point))
    return
Ejemplo n.º 9
0
async def force_setup(ctx, user: discord.Member, point, combo):
    if not (ctx.author.id in admin_ids): return
    member = Member(user)
    prev_point = member.get_point()
    prev_combo = member.get_combo()
    member.set_point(point)
    member.set_combo(combo)
    await ctx.send(
        "{:s}'s point and combo changed: {:d}, {:d} -> {:d}, {:d}".format(
            member.name, prev_point, prev_combo, point, combo))
    return
Ejemplo n.º 10
0
Archivo: bot.py Proyecto: 3-24/nalgang
async def nalgang(ctx, *, arg=""):
    member = Member(ctx.author)
    logger.info(
        f"Querying user (id={member.id}, guild={member.guild})'s nalgang...")
    if not member.exist_db():
        await ctx.channel.send("등록되지 않은 사용자입니다.")
        return

    msg = arg
    if len(msg) > 280: msg = msg[:280]

    message_time = ctx.message.created_at.replace(tzinfo=pytz.utc).astimezone(
        pytz.timezone(timezone))
    result = member.nalgang(msg, present_time=message_time)

    if result == None:
        await ctx.channel.send("{:s}님은 이미 날갱되었습니다.".format(member.name))
    else:
        point, combo_point = result
        await ctx.channel.send("{:s}님이 날갱해서 {:d}점을 얻었습니다!".format(
            member.name, point))
        if combo_point != 0:
            await ctx.channel.send("와! {:s}님이 전근으로 {:d}점을 얻었습니다!".format(
                member.name, combo_point))

    attendance_info = get_all_attendance_info(member.guild)
    description = ""
    for index, info in enumerate(attendance_info):
        name = discord.utils.escape_markdown(
            ctx.guild.get_member(info[0]).display_name)
        msg = info[1]
        description += str(index + 1) + ". " + name + ": " + msg + "\n"

    embed = discord.Embed(title="오늘의 날갱", description=description)
    await ctx.channel.send(embed=embed)
    return
Ejemplo n.º 11
0
Archivo: bot.py Proyecto: 3-24/nalgang
async def api_point_add(ctx, user: discord.Member, delta: int):
    member = Member(user)
    if not member.exist_db():
        await ctx.channel.send("등록되지 않은 사용자입니다.")
        return
    prev_point = member.get_point()
    if (prev_point + delta < 0):
        await ctx.send("점수가 부족합니다.")
        return
    member.set_point(prev_point + delta)
    if (delta >= 0):
        await ctx.send(
            f"{user.display_name}에게 {delta}점이 추가되었습니다. 이제 {member.get_point()}점입니다."
        )
    else:
        await ctx.send(
            f"{user.display_name}이 {-delta}점 잃었습니다. 이제 {member.get_point()}점입니다."
        )
    return
Ejemplo n.º 12
0
Archivo: test.py Proyecto: 3-24/nalgang
 def testNalgang(self):
     m1 = Member(None)
     m1.id = 1
     m1.guild = 2222
     m1.name = "Alice"
     m1.add_db()
     m1.nalgang("")
     self.assertEqual(m1.get_point(), config.point_by_rank[0])
     self.assertEqual(m1.get_combo(), 1)
     self.assertIsNone(m1.nalgang(""))
Ejemplo n.º 13
0
Archivo: bot.py Proyecto: 3-24/nalgang
async def give_point(ctx, user: discord.Member, point: int):
    if point <= 0: return

    member_send = Member(ctx.author)
    member_receive = Member(user)
    if not (member_send.exist_db() and member_receive.exist_db()):
        await ctx.channel.send("등록되지 않은 사용자입니다.")
        return

    if member_send.get_point() < point:
        await ctx.channel.send("점수가 부족합니다.")
        return

    member_send.give_point(member_receive, point)
    await ctx.channel.send("짜잔! {:s}님이 {:s}님에게 {:d}점을 선물했습니다.".format(
        member_send.mention(), member_receive.mention(), point))
    return
Ejemplo n.º 14
0
 def test_here(self):
     member = Member("John", "Doe")
     self.assertFalse(member.attended)
     member.here()
     self.assertTrue(member.attended)
Ejemplo n.º 15
0
Archivo: test.py Proyecto: 3-24/nalgang
 def testNalgangPreciseDayReset(self):
     m1 = Member(None)
     m1.id = 1
     m1.guild = 2222
     m1.add_db()
     m1.name = "Alice"
     m1.nalgang("", datetime(2020, 5, 7, hour=5, minute=59, second=59))
     self.assertEqual(m1.get_point(), config.point_by_rank[0])
     self.assertEqual(m1.get_combo(), 1)
     m1.nalgang("", datetime(2020, 5, 7, hour=6, minute=00, second=00))
     self.assertEqual(m1.get_point(), config.point_by_rank[0] * 2)
     self.assertEqual(m1.get_combo(), 2)
Ejemplo n.º 16
0
Archivo: test.py Proyecto: 3-24/nalgang
 def testNalgangDayReset(self):
     m1 = Member(None)
     m1.id = 1
     m1.name = "Alice"
     m1.guild = 2222
     m1.add_db()
     m1.nalgang("")
     self.assertEqual(m1.get_point(), config.point_by_rank[0])
     self.assertEqual(m1.get_combo(), 1)
     time1 = datetime.today() + timedelta(days=1)
     m1.nalgang("", time1)
     self.assertEqual(m1.get_point(), config.point_by_rank[0] * 2)
     self.assertEqual(m1.get_combo(), 2)
     time2 = datetime.today() + timedelta(days=2)
     m1.nalgang("", time2)
     self.assertEqual(m1.get_point(), config.point_by_rank[0] * 3)
     self.assertEqual(m1.get_combo(), 3)
Ejemplo n.º 17
0
Archivo: test.py Proyecto: 3-24/nalgang
 def testNalgangWeekBonus(self):
     m1 = Member(None)
     m1.id = 1
     m1.name = "Alice"
     m1.guild = 2222
     m1.add_db(combo=6)
     m1.nalgang("")
     self.assertEqual(m1.get_point(),
                      config.point_by_rank[0] + config.week_bonus)
     self.assertEqual(m1.get_combo(), 7)
Ejemplo n.º 18
0
async def look_up(ctx, user: discord.Member):
    if not (ctx.author.id in admin_ids): return
    member = Member(user)
    point = member.get_point()
    await ctx.send(str(point))
    return
Ejemplo n.º 19
0
Archivo: test.py Proyecto: 3-24/nalgang
 def testNalgangGuildDependent(self):
     m1 = Member(None)
     m1.id = 1
     m1.name = "Alice"
     m1.guild = 2222
     m1.add_db()
     m2 = Member(None)
     m2.id = 1
     m2.name = "Alice"
     m2.guild = 2223
     m2.add_db()
     m1.nalgang("")
     m2.nalgang("")
     self.assertEqual(m1.get_point(), config.point_by_rank[0])
     self.assertEqual(m2.get_point(), config.point_by_rank[0])