示例#1
0
    async def whois(self, ctx, *args):
        member = MemberConverter(ctx, args[0]).convert(
        ) if len(args) > 0 and args[0] else ctx.message.author
        server = ctx.message.server

        e = Embed()
        e.set_author(name=get_nick(member), icon_url=get_avatar(member))
        e.description = member.mention
        e.set_thumbnail(url=get_avatar(member))
        e.add_field(name="Status", value=member.status)
        e.add_field(name="Joined",
                    value=member.joined_at.strftime("%a %Y-%m-%d %H:%MUTC"))
        joinpos = 1
        for m in server.members:
            if m.joined_at < member.joined_at:
                joinpos += 1

        e.add_field(name="Join Position", value=str(joinpos))

        e.add_field(name="Registered",
                    value=member.created_at.strftime("%a %Y-%m-%d %H:%MUTC"))
        roleString = ""
        for rm in member.roles[1:]:
            roleString += rm.mention + "\t"
        e.add_field(name="Roles (" + str(len(member.roles) - 1) + ")",
                    value=roleString)

        await self.bot.say(embed=e)
示例#2
0
 async def unmute(self, ctx, *args):
     member = MemberConverter(ctx, args[0]).convert(
     ) if len(args) > 0 and args[0] else ctx.message.author
     server = ctx.message.server
     if server.id not in self.bot.audit_log.keys() or not is_mod(ctx):
         return
     if not get(member.roles, name="Muted"):
         await self.bot.say(
             f"The user: {str(member.name)}\#{str(member.discriminator)} was not muted."
         )
         return
     await self.bot.remove_rank(server, "Muted", member)
     e = Embed(
         title=
         f"Member: {str(member.name)}\#{str(member.discriminator)} unmuted",
         description=member.mention + " " + member.display_name,
         colour=0xFFFF00,
     )
     e.set_author(name=get_nick(member), icon_url=get_avatar(member))
     e.set_thumbnail(url=get_avatar(member))
     await self.bot.send_message(self.bot.get_channel(
         self.bot.audit_log[member.server.id]),
                                 embed=e)
     emojimeme = get(self.bot.get_all_emojis(), name='gladrad')
     await self.bot.add_reaction(ctx.message, emojimeme)
示例#3
0
 async def mute(self, ctx, *args):
     member = MemberConverter(ctx, args[0]).convert(
     ) if len(args) > 0 and args[0] else ctx.message.author
     server = ctx.message.server
     if server.id not in self.bot.audit_log.keys() or not is_mod(ctx):
         return
     if len(args) < 2 or not args[1].isdigit():
         await self.bot.say(
             "Invalid argument. Please specify a user and a time in minutes as a number."
         )
         return
     if get(member.roles, name="Muted"):
         await self.bot.say(
             f"The user: {str(member.name)}\#{str(member.discriminator)} was already muted."
         )
         return
     e = Embed(
         title=
         f"Member: {str(member.name)}\#{str(member.discriminator)} muted for {args[1]} minute(s)",
         description=member.mention + " " + member.display_name,
         colour=Colour.red(),
     )
     e.set_author(name=get_nick(member), icon_url=get_avatar(member))
     e.set_thumbnail(url=get_avatar(member))
     await self.bot.send_message(self.bot.get_channel(
         self.bot.audit_log[member.server.id]),
                                 embed=e)
     await self.bot.add_rank(server, "Muted", member)
     emojimeme = get(self.bot.get_all_emojis(), name='jellysad')
     await self.bot.add_reaction(ctx.message, emojimeme)
     await self.unmuteinternal(server, member, args[1])
示例#4
0
 async def avatar(self, ctx, *args):
     urMum = MemberConverter(ctx, args[0]).convert(
     ) if len(args) > 0 and args[0] else ctx.message.author
     e = Embed()
     e.set_author(name=get_nick(urMum), icon_url=get_avatar(urMum))
     e.set_image(url=get_avatar(urMum))
     await self.bot.say(embed=e)
示例#5
0
 async def unmuteinternal(self, server, member, time):
     await asyncio.sleep(int(time) * 60)
     if not get(member.roles, name="Muted"):
         return
     await self.bot.remove_rank(server, "Muted", member)
     e = Embed(
         title=
         f"{str(member.name)}\#{str(member.discriminator)}'s mute expired.",
         description=member.mention + " " + member.display_name,
         colour=0xFFFF00,
     )
     e.set_author(name=get_nick(member), icon_url=get_avatar(member))
     e.set_thumbnail(url=get_avatar(member))
     await self.bot.send_message(self.bot.get_channel(
         self.bot.audit_log[member.server.id]),
                                 embed=e)
示例#6
0
    async def copy_channel(self,
                           ctx,
                           from_channel: str,
                           to_channel: Channel,
                           to_filter=None,
                           limit=10000):
        if not is_mod(ctx): return

        from_channel = self.bot.get_channel(
            from_channel) or self.bot.get_channel(from_channel[2:-1])

        if from_channel is None:
            await self.bot.say("Invalid from_channel")
            return

        if to_filter == "image":

            def to_filter(msg: Message):
                if msg.attachments or msg.embeds:
                    return True
        else:
            # noinspection PyUnusedLocal
            def to_filter(msg: Message):
                return True

        msglist = []
        async for i in afilter(
                self.bot.logs_from(from_channel,
                                   before=dt.utcnow(),
                                   limit=limit), to_filter):
            msglist.append(i)

        for i in msglist[::-1]:
            i: Message = i

            embed = Embed()
            embed.set_author(name=get_nick(i.author),
                             icon_url=get_avatar(i.author))

            if len(i.attachments) == 1:
                embed.set_image(url=i.attachments[0]["url"])
            elif len(i.attachments) > 1:
                for ind, j in enumerate(i.attachments):
                    aembed = deepcopy(embed)
                    aembed.description = f"Image {ind+1}/{len(i.attachments)}"
                    aembed.set_image(url=j["url"])

                    await self.bot.send_message(to_channel, embed=aembed)

            if i.embeds:
                with (suppress(IndexError, KeyError)):
                    aembed = deepcopy(embed)
                    aembed.set_image(url=i.embeds[0]['image']['url'])

                    await self.bot.send_message(to_channel, embed=aembed)

            embed.description = i.content
            if embed.description or embed.image.url:
                await self.bot.send_message(to_channel, embed=embed)
示例#7
0
	def _avatar_save(self, f, t):
		if t == 'large':
			size = AVATAR_LARGE_SIZE
		elif t == 'medium':
			size = AVATAR_MEDIUM_SIZE
		elif t == 'small':
			size = AVATAR_SMALL_SIZE
		elif t == 'origin':
			size = 0
		else:
			return False
		if size:
			filename = get_avatar(MEDIA_ROOT + self._get_path('origin'), size)
			storage.save(self._get_path(t), File(open(filename)))
			remove(filename)
		else:
			if isinstance(f, File):
				storage.save(self._get_path(t), f)
			elif isinstance(f, file):
				storage.save(self._get_path(t), File(f))
			else:
				storage.save(self._get_path(t), File(open(f)))
示例#8
0
def onlive(video_data):
    data = {
        'title': text.PUSHALERT_TITLE.format(**video_data["metadata"]),
        "message": text.PUSHALERT_MESSAGE.format(**video_data["metadata"]),
        "url":
        f"https://www.youtube.com/watch?v={video_data['metadata']['id']}"
    }
    if const.PUSHALERT_ICON:
        data["icon"] = const.PUSHALERT_ICON
    else:
        data["icon"] = utils.get_avatar(video_data['metadata']["channelURL"])

    data = urllib.parse.urlencode(data).encode()

    req = urllib.request.Request(url="https://api.pushalert.co/rest/v1/send",
                                 data=data)
    req.add_header("Authorization", f"api_key={const.PUSHALERT_API_KEY}")

    try:
        return utils.urlopen(req)
    except:
        return
示例#9
0
def onlive(video_data):
    if "thumbnailUrl" in video_data['metadata']:
        image = video_data['metadata']["thumbnailUrl"]
    else:
        image = video_data['metadata']["thumbnail"]

    data = {
        "to": const.FCM_TARGET,
        "validateOnly": False,
        "notification": {
            'title': text.FCM_TITLE.format(**video_data["metadata"]),
            "body": text.FCM_MESSAGE.format(**video_data["metadata"]),
            "click_action":
            f"https://www.youtube.com/watch?v={video_data['metadata']['id']}",
            "image": image
        }
    }

    if const.FCM_ICON:
        data["notification"]["icon"] = const.FCM_ICON
    else:
        data["notification"]["icon"] = utils.get_avatar(
            video_data['metadata']["channelURL"])

    data = json.dumps(data).encode()

    req = urllib.request.Request(url="https://fcm.googleapis.com/fcm/send",
                                 method="POST",
                                 data=data)
    req.add_header('Content-Type', 'application/json')

    req.add_header("Authorization", f"key={const.FCM_API_KEY}")

    try:
        return utils.urlopen(req)
    except:
        return
示例#10
0
def login():
    form = LoginForm()
    if session.get('username'):
        return redirect(url_for('shake_and_dice'))
    if request.method == 'GET':
        return render_template('login.html', form=form)
    else:
        username = form.username.data
        password = form.password.data
        password_md5 = md5(password)
        avatar = form.avatar.data

        user = User.query.filter_by(username=username).first()

        if user:

            if password_md5 != user.password:
                return render_template(
                    'login.html',
                    form=form,
                    message='Sorry, username or password ERROR!')
            else:
                session['username'] = username
                return redirect(url_for('shake_and_dice'))
        else:
            user = User(username=username,
                        password=password_md5,
                        avatar=avatar)
            db.session.add(user)
            db.session.commit()
            session['username'] = username

        data = get_avatar(username)
        mark_data(username, data)

        return redirect(url_for('shake_and_dice'))
示例#11
0
def get_contact(bot, update, user_data):
    print(update.message.contact)
    update.message.reply_text('Thanks for your contact {}'.format(
        get_avatar(user_data)),
                              reply_markup=get_keyboard())
示例#12
0
def get_location(bot, update, user_data):
    print(update.message.location)
    update.message.reply_text('Thanks for your location {}'.format(
        get_avatar(user_data)),
                              reply_markup=get_keyboard())