コード例 #1
0
	async def mcskin_raw(self, ctx, input, hat=True) :
		try :
			uuid, username = await self.get_us_or_uu(input)
		except UUIDNotFound :
			await ctx.send(embed=embed_em(ctx, self.ss('UUIDNotfound')))
			return
		except UsernameNotFound :
			await ctx.send(embed=embed_em(ctx, self.ss('UsernameNotfound')))
			return


		avatar_url = 'https://crafatar.com/avatars/{}{}'.format(uuid, '?overlay' if hat else '')
		skin_url = 'https://crafatar.com/skins/{}'.format(uuid)
		# r = await b.session.get(avatar_url)
		# if r.status != 201 :
		# 	await ctx.send(embed=embed_em(ctx, self.ss('UUIDNotfound')))
		# 	return
		#
		# r = await b.session.get(body_url)
		# if r.status != 201 :
		# 	await ctx.send(embed=embed_em(ctx, self.ss('UUIDNotfound')))
		# 	return

		e = embed_t(ctx)
		e.set_author(name=username, icon_url=avatar_url)
		e.set_image(url=skin_url)
		e.set_footer(text=uuid)
		if not hat :
			e.add_field(name=ctx.bot.ss('Configs'), value='- ' + self.ss('NoHat'))
		await ctx.send(embed=e)
コード例 #2
0
	async def guild(self, ctx, guild_id = None) :
		guild = ctx.message.guild if isinstance(ctx.message.channel, discord.TextChannel) else None
		if not guild :
			if not isinstance(ctx.message.channel, discord.TextChannel) :
				if guild_id == None :
					err = embed_em(ctx, ctx.bot.ss("ObjectNotFoundInObject").format(ctx.bot.ss('Model', 'Guild'), ctx.bot.ss('Model', 'DMChannel')))
			else :
				err = embed_em(ctx, ctx.bot.ss("ObjectNotFoundFromObject").format(ctx.bot.ss("Model", "Guild"), str(guild_id)))
			await ctx.send(embed=err)
		else :
			await ctx.send(embed=model_info(ctx, guild))
コード例 #3
0
	async def emoji(self, ctx, emoji_text) :
		emoji, passed = await anyemoji_convert(ctx, emoji_text)
		if passed == -1 :
			err = embed_em(ctx, ctx.bot.ss("ObjectNotFoundFromObject").format(ctx.bot.ss("Model", "Emoji"), emoji_text))
			#err.description = "```{}```".format(result.text)
			await ctx.send(embed=err)
			return

		b = emoji[0]
		if passed == 0 :
			etext = ""

			f = "{}__emoticon_{}.png".format(ctx.bot.bot_name.lower(), "-".join([format(ord(e), 'x') for e in emoji_text]))
		else :
			emoji = emoji[1]
			if passed == 4 :
				f = "{}__emoticon_{}{}-174d{}.{}".format(ctx.bot.bot_name.lower(), "animated_" if emoji.animated else "", emoji.name, emoji.id, "gif" if emoji.animated else "png")
			elif passed < 4 :
				try :
					u = emoji.user
					uid = emoji.user.id
					f = "{}__emoticon_{}{}-174d{}_{}-168d{}_{}-169d{}.{}".format(ctx.bot.bot_name.lower(), "animated_" if emoji.animated else "", emoji.name, emoji.id, u, uid, emoji.guild_id, emoji.guild.name, "gif" if emoji.animated else "png")
				except :
					f = "{}__emoticon_{}{}-174d{}.{}".format(ctx.bot.bot_name.lower(), "animated_" if emoji.animated else "", emoji.name, emoji.id, "gif" if emoji.animated else "png")
			else :
				f = "{}__emoticon".format(ctx.bot.bot_name.lower())

		file = discord.File(fp=b, filename=f)
		await ctx.send(file=file)
コード例 #4
0
	async def rtx(self, ctx) :
		img = await getLastImage(ctx, 2)
		if len(img or []) < 2 :
			e = embed_em(ctx, ctx.bot.ss('AnErrorOccurred'), ctx.bot.ss('ImageNotEnoughNeedNum').format(str(2)))
			await ctx.send(embed=e)
			return
		file = await processing_image_to_file(ctx, "rtx", self.m_rtx, img[1], img[0])
		await ctx.send(file=file)
コード例 #5
0
ファイル: ImageFilter.py プロジェクト: gongpha/PaiDiscord
    async def resize(self,
                     ctx,
                     width: str,
                     height: typing.Optional[str] = "asWidth",
                     resample: typing.Optional[str] = "bilinear"):
        im = await getLastImageOrAnimatedImage(ctx)
        try:
            if width.endswith("%"):
                w = int((int(width.replace('%', '')) / 100) * im.width)
            else:
                w = width

            if height == "asWidth":
                if width.endswith("%"):
                    h = int((int(width.replace('%', '')) / 100) * im.height)
                else:
                    h = w
            else:
                if height.endswith("%"):
                    h = int((int(height.replace('%', '')) / 100) * im.height)
                else:
                    h = height
            if int(w) <= 0:
                w = 1
            if int(h) <= 0:
                h = 1
        except ValueError:
            e = embed_em(ctx, self.ss('Resize__CannotResizeThisImage'),
                         self.bot.ss('InvalidNumber'))
            await ctx.send(embed=e)
            return
        try:
            file = await processing_image_to_file(ctx, "resize", resize_img_b,
                                                  im, w, h, resample)
        except Image__Failed:
            e = embed_em(ctx, self.ss('Resize__CannotResizeThisImage'),
                         self.ss('Resize__TryReduceSize'))
            await ctx.send(embed=e)
            return
        await ctx.send("`{} x {}` => `{} x {}`".format(int(im.width),
                                                       int(im.height), int(w),
                                                       int(h)),
                       file=file)
コード例 #6
0
async def AnyModel_FindUserOrMember(ctx,
                                    object,
                                    external=True,
                                    in_ctx_guild=True):
    r = await AnyModel__MemberOrUser_Optional(ctx, object, external,
                                              in_ctx_guild)
    if not r:
        err = embed_em(
            ctx,
            ctx.bot.ss("ObjectNotFoundFromObject").format(
                ctx.bot.ss("Model", "User"), str(object)))
        #err.description = "```{}```".format(result.text)
        await ctx.send(embed=err)
        return None
    return r
コード例 #7
0
    async def on_command_error(self, ctx, error):
        cmdn = ctx.message.content.split(' ')[0]
        if isinstance(error, commands.CommandNotFound):
            return
        elif isinstance(error, commands.MissingRequiredArgument):
            await ctx.send(embed=embed_em(
                ctx, self.ss('InCorrectArgument'),
                "```{} {}```".format(cmdn, ctx.command.usage
                                     ) if ctx.command.usage != None else ''))
            return
        elif isinstance(error, commands.NoPrivateMessage):
            await ctx.send(
                embed=embed_wm(ctx, ctx.bot.ss("CommandInDMNotAvailable")))
            return
        elif isinstance(error, commands.MissingPermissions):
            l = ('\n'.join(
                ctx.bot.ss("NoPermissionWith").format(
                    ctx.bot.ss("Permission", string))
                for string in error.missing_perms)
                 ) if error.missing_perms else ctx.bot.ss("None")
            await ctx.send(embed=embed_em(ctx, l))
            return
        elif isinstance(error, commands.NotOwner):
            await ctx.send(embed=embed_em(ctx, ctx.bot.ss("YouAreNotBotOwner"))
                           )
            return
        elif isinstance(error, commands.CheckFailure):
            await ctx.send(embed=embed_em(ctx, error)
                           )  # ctx.bot.ss("AnErrorOccurred")
            return

        e = discord.Embed(title="Command Error : `{}{}`".format(
            self.cmdprefix if ctx.command.name != None else "",
            ctx.command.name if ctx.command.name != None else "UNKNOWN"))
        e.description = f"Called to `{self.bot_name}`"
        e.set_author(name='From {0} ({0.id})'.format(ctx.message.author),
                     icon_url=ctx.message.author.avatar_url)
        e.add_field(name='Guild',
                    value='`{0.name}` ({0.id})'.format(ctx.message.guild)
                    if ctx.message.guild else 'Direct Message')
        e.add_field(
            name='Channel',
            value='`{0.name}` ({0.id})'.format(ctx.message.channel)
            if ctx.message.guild else
            'DM with `{0.recipient}` ({0.id})'.format(ctx.message.channel))
        e.add_field(name='Message',
                    value="(" + str(ctx.message.id) + ")\n" +
                    ctx.message.jump_url + "\n```" + ctx.message.content +
                    "```",
                    inline=False)
        e.color = 0xff0000
        e.timestamp = ctx.message.created_at

        error = getattr(error, 'original', error)

        traceback.print_exception(type(error),
                                  error,
                                  error.__traceback__,
                                  file=sys.stderr)

        tb = error.__traceback__
        f = tb.tb_frame
        lineno = tb.tb_lineno
        filename = f.f_code.co_filename

        e.add_field(name='Expection',
                    value="(" + str(ctx.message.id) + ")\n```" +
                    str(getattr(error, 'original', error)) + "```",
                    inline=False)
        e.add_field(name='Filename', value=filename, inline=True)
        e.add_field(name='Line No.', value=lineno, inline=True)
        await self.get_bot_channel("system", "error").send(embed=e)
コード例 #8
0
    async def covid_stat(self, ctx, minimal=False):
        response = await ctx.bot.session.get(stat_url)
        try:
            data = (await response.json())[0]
        except:
            err = embed_em(ctx, self.bot.ss("CannotReceiveDocument"))
            await ctx.send(embed=err)
            return
        curr_datetime = datetime.strptime(data["update_date"],
                                          '%Y-%m-%d %H:%M:%S')
        datestr = local_strftime(ctx, curr_datetime, get_time_format(ctx))

        total_hosp = data["total_case"] - data["total_recovered"] - data[
            "total_death"]
        new_hosp = data["new_case"] - data["new_recovered"] - data["new_death"]

        #	DATA1						DATA2					POSITIVE	EMOJI
        dataformat = [
            [data["total_case"], data["new_case"], False, 'mask'],
            [data["total_death"], data["new_death"], False, 'skull'],
            [
                data["total_recovered"], data["new_recovered"], True,
                'sparkling_heart'
            ],
            [total_hosp, new_hosp, False, 'hospital'],
        ]

        #	0							1						2			3

        # OLD
        #dataformat = {
        #	"case" : ('mask', False),
        #	"death" : ('skull', False),
        #	"new_recovered" : ('sparkling_heart', True),
        #	"Hospitalized" : ('hospital', False)
        #}

        blank_emoji = ctx.bot.get_resource(':black_small_square:', 'Emojis',
                                           'General', 'blank')

        def digits_gen(number, max_length, symbol=False, positive=True):
            numstr = ("zero", "one", "two", "three", "four", "five", "six",
                      "seven", "eight", "nine")
            if symbol:
                resstr = ctx.bot.get_resource("", 'Emojis', 'General', ((
                    ("up_green" if number > 0 else "down_red") if positive else
                    ("up_red" if number > 0 else "down_green")))
                                              if number != 0 else "blank")
            else:
                resstr = ""
            number = str(abs(number))
            if len(number) < max_length:
                resstr += blank_emoji * (max_length - len(number))
            for c in number:
                resstr += ':{}:'.format(numstr[int(c)])
            return resstr

        tempstr = ":{}:{}{}"
        await ctx.send(embed=embed_t(ctx,
                                     self.ss("title"),
                                     description=datestr + "\n\n" +
                                     self.ss("ddc_moph"),
                                     casesensitive=False))
        final = [
            tempstr.format(
                topic[3], blank_emoji + digits_gen(
                    topic[0], max([len(str(abs(c[0])))
                                   for c in dataformat])) + blank_emoji,
                digits_gen(topic[1],
                           max([len(str(abs(c[1])))
                                for c in dataformat]), True, topic[2]))
            for topic in dataformat
        ]
        if minimal:
            await ctx.send("\n".join(final))
        else:
            for f in final:
                await ctx.send(f)