async def ko(self, pgr: Pager, member): now = datetime.datetime.now() warns = pgr.get_thispage() if not warns: return discord.Embed(title=f"🚨 {member} 님의 경고가 하나도 없습니다!", color=self.cog.color["warn"]) embed = discord.Embed(title=f"🚨 {member} 님의 경고 목록", description="", color=self.cog.color["warn"]) for one in warns: embed.description += """\ **{}** ({}회) > {}, By {} """.format( one["reason"], one["count"], " ".join( list(timedelta.format_timedelta(now - one["dt"]).values())[0]) + " 전" if one["dt"] <= now - datetime.timedelta(minutes=1) else "방금", self.ctx.guild.get_member(one["warnby"]) if self.ctx.guild.get_member(one["warnby"]) else "(알 수 없음)", ) return embed
def warns_embed(cog: BaseCog, pgr: Pager, *, member: discord.Member, mode='default'): warns = pgr.get_thispage() embed = discord.Embed(title=f'🚨 {member} 의 경고 목록', description='', color=colors.WARN) for idx, one in enumerate(warns, 1): td = datetime.datetime.now() - one['dt'] if td < datetime.timedelta(minutes=1): pubtime = '방금' else: pubtime = list(timedelta.format_timedelta(td).values())[0] + ' 전' bymem = member.guild.get_member(one['byuser']) if bymem: bystr = f', By {bymem.mention}' else: bystr = f', By (알수없는 유저)' if mode == 'select': embed.description += '{}. **{}**\n> {}{}\n'.format( idx, one['reason'], pubtime, bystr) else: embed.description += '**{}**\n> {}{}\n'.format( one['reason'], pubtime, bystr) embed.set_footer(text='❌: 경고 취소하기') return embed
def before_request(): g.headers = {} g.pagination = Pager(request.args) g.request = Request(request) g.auth = None g.perms = {} g.im_rds = rds cnf = MYSQL g._db = Mysql(*cnf) g._imdb = g._db
async def ko(self, pgr: pager.Pager, *, total: int): embed = discord.Embed(title='📰 뉴스', description='', color=self.cog.color['info']) for one in pgr.get_thispage(): if one.content: if one.content.__len__() > 110: content = '> ' + one.content[:110] + '...\n' else: content = '> ' + one.content + '\n' else: content = '' td = datetime.datetime.now() - one.datetime if td < datetime.timedelta(minutes=1): pubtime = '방금' else: pubtime = list(timedelta.format_timedelta(td).values())[0] + ' 전' embed.description += f'🔹 **`{one.title}`**\n{content}**- {one.company}**, {pubtime}\n\n' if total > 40: embed.description += '```{}/{} 페이지, 전체 {}건 중 최신 {}건```'.format(pgr.now_pagenum()+1, len(pgr.pages()), total, pgr.objlen()) else: embed.description += '```{}/{} 페이지, 전체 {}건```'.format(pgr.now_pagenum()+1, len(pgr.pages()), pgr.objlen()) embed.set_footer(text='* 이 뉴스는 재미 및 게임 플레이를 위한 실제와 상관없는 픽션임을 알려 드립니다.') return embed
def get(self, req): pn = req.GET.get('pn') current_page = int(pn) per_page = 10 pg_num = 5 res = models.Server.objects.all().values(*[i['q'] for i in self.tb_config if i['q']]) total_pg = math.ceil(len(res)/per_page) pager = Pager.makePager(pg_num, current_page, total_pg) data = { "tb_config": self.tb_config, 'tb_data':list(res[per_page*(current_page-1):per_page*current_page]), 'pager':pager, 'global_dict':{ # 'asset_id': list(models.Asset.objects.all().values_list('id','name')), } } return data
def get(self, req): pn = req.GET.get('pn') Condtions = req.GET.get('packageCondtions') if Condtions: q = Conditions.makeQ(json.loads(Condtions)) res = models.Asset.objects.filter(q).values( *[i['q'] for i in self.tb_config if i['q']]) else: res = models.Asset.objects.all().values( *[i['q'] for i in self.tb_config if i['q']]) current_page = int(pn) per_page = 10 pg_num = 5 total_pg = math.ceil(len(res) / per_page) pager = Pager.makePager(pg_num, current_page, total_pg) data = { "tb_config": self.tb_config, 'tb_data': list(res[per_page * (current_page - 1):per_page * current_page]), 'pager': pager, 'global_dict': { 'device_status_id': models.Asset.device_status_choices, 'device_type_id': models.Asset.device_type_choices, 'idc_id': list(models.IDC.objects.all().values_list('id', 'name')), 'business_unit_id': list(models.BusinessUnit.objects.all().values_list( 'id', 'name')), 'department_id': list(models.Department.objects.all().values_list()), } } return data
def before_request(): g.headers = {} g.pagination = Pager(request.args) g.request = Request(request) g.auth = None g.perms = {}
async def _warns(self, ctx: commands.Context, member: Optional[discord.Member] = None): async with self.pool.acquire() as conn: async with conn.cursor(aiomysql.DictCursor) as cur: if not member: member = ctx.author if await cur.execute( 'select * from warns where user=%s order by `dt` desc limit 10', member.id) == 0: await ctx.send(f'{member} 가 받은 경고가 하나도 없습니다! 👍') return warns = await cur.fetchall() pgr = Pager(warns, 5) msg = await ctx.send( embed=manageembeds.warns_embed(self, pgr, member=member)) ismaster = ctx.author.id in masters.MASTERS if ismaster: extemjs = ['❌'] else: extemjs = [] emjs = emojibuttons.PageButton.emojis + extemjs async def addreaction(m): if len(pgr.pages()) == 0: return elif len(pgr.pages()) <= 1: for emj in extemjs: await m.add_reaction(emj) else: for emj in emjs: await m.add_reaction(emj) await addreaction(msg) def check(reaction, user): return user == ctx.author and msg.id == reaction.message.id and reaction.emoji in emjs while True: try: reaction, user = await self.bot.wait_for( 'reaction_add', check=check, timeout=60 * 5) except asyncio.TimeoutError: try: await msg.clear_reactions() except: pass else: if reaction.emoji in extemjs: if not ctx.channel.last_message or ctx.channel.last_message_id == msg.id: await msg.edit(embed=manageembeds.warns_embed( self, pgr, member=member, mode='select')) else: results = await asyncio.gather( msg.delete(), ctx.send(embed=manageembeds.warns_embed( self, pgr, member=member, mode='select'))) msg = results[1] await addreaction(msg) reaction.message = msg if reaction.emoji == '❌' and ismaster: allcancel = ['모두', '전부'] itemidxmsg = await ctx.send(embed=discord.Embed( title='🚨 경고 취소하기 - 취소할 경고 선택', description= '취소할 경고의 번째수를 입력해주세요. (모두 취소하려면 `전부` 또는 `모두` 입력)\n위 메시지에 경고 앞마다 번호가 붙어 있습니다.\n❌를 클릭해 취소합니다.', color=colors.WARN)) await itemidxmsg.add_reaction('❌') canceltask = asyncio.create_task( event_waiter.wait_for_reaction(self.bot, ctx=ctx, msg=itemidxmsg, emojis=['❌'], timeout=60)) indextask = asyncio.create_task( event_waiter.wait_for_message( self.bot, ctx=ctx, timeout=60, subcheck=lambda m: m.content.isdecimal( ) or m.content in allcancel)) task = await event_waiter.wait_for_first( canceltask, indextask) await itemidxmsg.delete() if task == indextask: idxtaskrst = indextask.result() if idxtaskrst.content in allcancel: await cur.execute( 'delete from warns where user=%s', member.id) lsnr = self.getlistener('on_warn') await lsnr(member) else: idx = int(idxtaskrst.content) if 1 <= idx <= len(pgr.get_thispage()): delwarn = pgr.get_thispage()[idx - 1] await cur.execute( 'delete from warns where uuid=%s', delwarn['uuid']) await ctx.send(embed=discord.Embed( title='{} 경고를 풀었습니다!'.format( self.emj.get(ctx, 'check')), color=colors.SUCCESS)) lsnr = self.getlistener('on_warn') await lsnr( ctx.guild.get_member( delwarn['user'])) else: embed = discord.Embed( title='❓ 경고 번째수가 올바르지 않습니다!', description= '위 메시지에 경고 앞마다 번호가 붙어 있습니다.', color=colors.ERROR) embed.set_footer( text='이 메시지는 7초 후에 사라집니다') await ctx.send(embed=embed, delete_after=7) if await cur.execute( 'select * from warns where user=%s order by `dt` desc limit 10', member.id) == 0: await msg.edit( content=f'{member} 가 받은 경고가 하나도 없습니다! 👍', embed=None) try: await msg.clear_reactions() except: pass return else: pgr.set_obj(await cur.fetchall()) do = await emojibuttons.PageButton.buttonctrl(reaction, user, pgr, double=5) if asyncio.iscoroutine(do): await asyncio.gather( do, msg.edit(embed=manageembeds.warns_embed( self, pgr, member=member)), )