Ejemplo n.º 1
0
    async def roleid(self, ctx, *role_name: str):
        try:
            role, le = utils.get_rid(ctx, role_name)  # getting IDs
            if le == 1:  # if only one ID returned
                role = ctx.guild.get_role(role[0])
                await ctx.send(content=role.id)

            else:  # if more than one result - giving all possible roles
                emby = discord.Embed(title="Multiple possible roles", color=discord.Color.blue())
                possible_roles = ""
                for r in role:  # iterating trough roles
                    print(r)
                    r = ctx.guild.get_role(r)
                    i = 0
                    for members in r.members:  # counting members
                        i += 1
                    possible_roles += "%s with %s members - ID: %s\n" % (r.mention, i, r.id)

                emby.add_field(name="Which one do you mean?", value=possible_roles)
                emby.set_footer(text="To get an easy copy-pasteable ID mention the role you mean")
                await ctx.send(embed=emby)

        except:
            emby = discord.Embed(title="", color=discord.Color.red())
            emby.add_field(name="Something went wrong", value="Please check your given argument.\n"
                                                              "Note that name inputs are handled case-sensitive and spaces in names might cause trouble.\n"
                                                              "Syntax: `%smembers <@role | role id | role name>`" % PREFIX)
            emby.set_footer(
                text="If you did everything right and this error keeps occurring, please contact the bot owner %s" % OWNER_NAME)
            await ctx.send(embed=emby)
Ejemplo n.º 2
0
def access(request):
    code = request.GET.get('code')
    result = get_id(code)
    token = result['access_token']
    openid = result['openid']
    try:
        account.objects.get(openid=openid)
    except:
        wxname = get_wxname(token, openid)
        account.objects.create(openid=openid, wxname=wxname, point=0)
    rid = get_rid(openid)
    youmi_url = r'http://w.ymapp.com/wx/ios/lists.html?r=' + rid
    return HttpResponseRedirect(youmi_url)
Ejemplo n.º 3
0
    async def setup_voice(self, ctx, role=None):
        await ctx.trigger_typing()
        ov = {
            ctx.guild.default_role:
            discord.PermissionOverwrite(view_channel=True,
                                        connect=True,
                                        speak=True)
        }

        if role:  #if there was a role as input - making custom overwrite
            role, leng = utils.get_rid(ctx, [role])
            role = ctx.guild.get_role(role[0])
            print(role)
            if role:
                ov = {
                    ctx.guild.default_role:
                    discord.PermissionOverwrite(view_channel=False,
                                                connect=False,
                                                speak=False),
                    role:
                    discord.PermissiosnOverwrite(view_channel=True,
                                                 connect=True,
                                                 speak=True)
                }
            else:
                await ctx.send(embed=utils.make_embed(value="Hey, the given id is invalid,\
								I'm trying to create the channels but with the default settings."                                                                                     ,\
                    name="No valid role", color=discord.Color.orange()))
        #creating channels
        cat = await ctx.guild.create_category_channel(
            "Voice Channels", overwrites=ov, reason="Created voice setup")
        await cat.edit(overwrites=ov,
                       position=0)  #move up didn't work in the creation
        pub_ch = await ctx.guild.create_voice_channel(
            "╔create-voice-channel",
            category=cat,
            reason="Created voice setup")
        priv_ch = await ctx.guild.create_voice_channel(
            "╠new-private-channel", category=cat, reason="Created voice setup")
        db = sqltils.DbConn(db_file, ctx.guild.id, "setting")
        #checking if db has three entries for one of those settings
        if len(db.search_table(value="pub-channel", column="setting")) < config.SET_LIMIT \
        or len(db.search_table(value="priv-channel", column="setting")) < config.SET_LIMIT:
            db.write_server_table(
                ("pub-channel", "value_name", pub_ch.id,
                 time.strftime("%Y-%m-%d %H:%M:%S"), config.VERSION_SQL))
            db.write_server_table(
                ("priv-channel", "value_name", priv_ch.id,
                 time.strftime("%Y-%m-%d %H:%M:%S"), config.VERSION_SQL))

            await ctx.send(embed=utils.make_embed(name="Sucessfully setup voice category",\
               value="You're category is set, have fun!\n \
						Oh, yeah - you can change the channel names how ever you like :)"                                                                                , color=discord.Color.green()))

        else:  #if channel max was reached
            await ctx.send(embed=utils.make_embed(
                name="Too many channels!",
                value=
                f"Hey, you can't make me watch more than {config.SET_LIMIT} channels per creation type.\n\
							If you wanna change the channels I watch use \
							`{config.PREFIX}ds [channel-id]` to remove a channel from your settings\n \
							The channels were created but aren't watched, have a look at `{config.PREFIX}help settings`\
							to add them manually after you removed other watched channels from the settings"
            ))
Ejemplo n.º 4
0
	async def members(self, ctx, *role: str):
		await ctx.trigger_typing()
		try:
			#testing if there was a first number argument that gives the number of ebends to show
			#like a parameter in bash
			#identifying the parameter by checking for lenght (avoid role id), for more than one given argument and by trying to convert to integer
			emb_req = 1 #setting var to default
			try: #fails when no role argument is given

				if len(role[0]) < 12 and len(role) > 1:
					emb_req = int(role[0])
					role = role[1:] #cutting first vakue from "role name"
			except: #ignoring everything
				None

			#getting role-id and the actual role object (a role id is 18 characters long)
			role, le = utils.get_rid(ctx, role)
			if le > 1:
				emby = discord.Embed(title="Multiple possible roles", color=discord.Color.blue())
				possible_roles = ""
				for r in role: #iterating trough roles
					r = ctx.guild.get_role(r)
					i = 0
					for members in r.members: #counting members
						i += 1
					possible_roles += "%s with %s members - ID: %s\n" %(r.mention, i, r.id)

				emby.add_field(name="Which one do you mean?", value=possible_roles)
				emby.set_footer(text="To get the actual information you need to use the id or a mention of the role")
				await ctx.send(embed=emby)

			#if only one role is possible
			else:
				role = ctx.guild.get_role(role[0])
				#setting up for loop
				emby = discord.Embed(title="Members in %s" %role.name, color=discord.Color.green())
				role_members = "" #contains members list
				role_bots = ""  #contains bot list
				i_members = 0   #contains the members
				i_bots = 0      #contains the bot count
				#print(type(role.members))


				members_list = []
				bots_list = []

				#await ctx.send(content = self.bot.get_emoji(462278332583510037))
				for member in role.members: #iterating trough members and adding to list, icreasaing also counter

					#adding a custom emoji that shows the status of the listed member
					#emotes will be loaded from a switch in environment.py
					if str(member.mobile_status) == "online":
						status_emoji = self.bot.get_emoji(EMOTE_SWITCH.get("mobile"))
					else:
						status_emoji = self.bot.get_emoji(EMOTE_SWITCH.get(str(member.status)))

					if member.bot == True: #checking if bot
						i_bots += 1
						#bots_list.append("%s %s" %(member.mention, status_emoji))
						bots_list.append(f"{member.mention} " + f"{status_emoji}".rjust(20))
					else: #human
						i_members += 1
						members_list.append("%s %s" %(member.mention, status_emoji))
				

				#an embed can't contain an empty field
				#so if there is no bot or human in this role this section replaces the emty field with the text "None"
				if not members_list:
					members_list.append("None")
				if not bots_list:
					bots_list.append("None")

				#checking if user can request more than one embed
				#first value: Amount of Embed Messages, second Number of fields per embed
				switch_admin = {
					True: [emb_req, 6],
					False: [1, 3]
				}

				#preparing the embeds
				#checking for admin perms, because only admins should be able to spam the channel
				props = switch_admin.get(ctx.author.guild_permissions.administrator)
				
				head = "Members [%s] " %(len(role.members))     #first field title of embed
				#creating Embeds is function (returns a list of embed objects)
				embys = utils.make_emby(emby, head, members_list, embed_limit=props[0], field_limit=props[1])   

				#sending multiple embeds - the last embed will be sent out when bots is finished (bellow)
				i = 0 #counter for making sure the last one stays
				for emby in embys:
					if i < len(embys)-1:
						await ctx.trigger_typing()
						await ctx.send(embed=emby)
						time.sleep(0.3) #waiting - don't spam the API too much!
					i += 1
				
				await ctx.trigger_typing()
				head = "Bots [%s]" %(i_bots) #head for bot section
				embys = utils.make_emby(emby, head, bots_list)
				i = 0 #counting embys
				for emby in embys:
					i +=1
					if i == len(embys): #setting footer in the last embed possible
						emby.set_footer(text="Role ID: %s" %role.id)
					await ctx.trigger_typing()
					await ctx.send(embed=emby)
					
			
		#this triggers when no ID or Role was given
		except: 
			emby = discord.Embed(title="", color=discord.Color.red())
			emby.add_field(name="Something went wrong", value="Please check your given argument.\n"
							"Note that name inputs are handled case-sensitive and spaces in names might cause trouble.\n"
							"Syntax: `%smembers <messages> <@role | role id | role name>`"%PREFIX)
			emby.set_footer(text="If you did everything right and this error keeps occuring, please contact the bot owner %s" %OWNER_NAME)
			await ctx.send(embed = emby)