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)
def testNalgang(self): m1 = Member(None) m1.id_num = 1 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(""))
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)
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)
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])
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
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
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)
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