예제 #1
0
async def set_mod_role():
    global admin_role
    try:
        admin_role = admin_role = client.get_guild(
            458765854624972811).get_role(458767248367157278), client.get_guild(
                458765854624972811).get_role(882726753074819124)
    except AttributeError:
        log.critical(f"FAU mod role not found, oof")
예제 #2
0
def get_target_voice_connection(object: Union[discord.Member, discord.Guild, discord.VoiceChannel, int]) -> Union[discord.VoiceClient, MusicException]:
	target = None

	if isinstance(object, discord.Member):
		target = getattr(object.voice, "channel", None)
	if isinstance(object, discord.Guild):
		target = getattr(discord.utils.find(lambda x: x.guild.id == object.id, client.voice_clients), "channel", None)
	if isinstance(object, discord.VoiceChannel):
		target = object

	if isinstance(object, int):
		# seriously :/
		log.warning("get_target_voice_channel() given a raw integer/ID; this probably should not happen but I'll try my best")

		channel = client.get_channel(object)
		guild = client.get_guild(object)
		if isinstance(guild, discord.Guild):
			target = discord.utils.find(lambda x: x.id == object, client.voice_clients).channel

		elif isinstance(channel, discord.VoiceChannel):
			target = channel

		else:
			target = None

	if not isinstance(target, discord.VoiceChannel):
		return None
	# now we know that target is a VoiceChannel
	if not check_if_user_in_channel(target, client.user.id):
		# if we're not in the channel
		return NotConnectedException("We're not currently connected to this voice channel")
	else:
		return discord.utils.find(lambda x: x.channel.id == target.id, client.voice_clients)
예제 #3
0
async def on_raw_reaction_remove(payload):

    json_file = loads(read('config.json'))
    single_roles_orientations = json_file['autoroles'][
        'single_roles_orientations']

    guild = client.get_guild(payload.guild_id)
    channel = client.get_channel(payload.channel_id)
    message = await channel.fetch_message(payload.message_id)
    member = guild.get_member(payload.user_id)

    if not channel == vrb.autoroles_chan1 and not channel == vrb.autoroles_chan2 or member == client.user:
        return
    if len(message.content.split('\n')) > 1:
        role_name = message.content.split('\n')[-1].split(' - ')[0][2:-2]
    elif len(message.embeds) == 0:
        role_name = message.content.split(' - ')[0][2:-2]
    else:
        role_name = message.embeds[0].fields[0].name
    role = get(guild.roles, name=role_name)

    await member.remove_roles(role)

    if role.id in single_roles_orientations and not chk_list_cohesion(
        [role.id for role in member.roles], single_roles_orientations):
        await member.add_roles(vrb.nie_zarucham)
예제 #4
0
def random_member_from_server(server_id: int,
                              require_human=False) -> discord.Member:
    '''
    Returns a random member from a server
    '''
    server: discord.Guild = bot.get_guild(server_id)

    if require_human:
        members = [m for m in server.members if not m.bot]
    else:
        members = server.members

    return random.choice(members)
async def ready_get_count():
	global other_roles, record, reputation, last_count, last_rep
	other_roles = [x.id for x in client.get_guild(key.awoobis_guild).roles if x.id != key.awoobis_worshiper_role]
	every_msg_ever = []
	for ch in client.get_guild(key.awoobis_guild).text_channels:
		every_msg_ever.extend(await ch.history(limit=None, reverse=True).flatten())
	every_msg_ever = sorted(every_msg_ever, key=lambda x: x.created_at)
	i = 0
	log.info(f"Now processing {len(every_msg_ever)} messages in the entire server...")
	for msg in every_msg_ever:
		i += 1
		if i % 5000 == 0:
			log.info(f"Processed {i} messages...")
		if msg.author.bot:
			continue
		try:
			target, drep = get_rep(msg.content, msg.author.id)  # "drep" = delta rep
		except:  # it's probably just some random text and not an id or mention
			continue
		if (target is None) or (drep is 0):
			pass
		else:
			if msg.created_at - last_rep.get(msg.author.id, datetime.datetime(2015, 5, 15, 0, 0, 0)) > datetime.timedelta(seconds=key.rep_cooldown):
				if target not in [key.awoobis_id, key.awoobot_id]:
					reputation[target] += drep
					last_rep[msg.author.id] = msg.created_at
				if target in [key.awoobis_id, key.awoobot_id]:
					if drep == -1:
						continue
					reputation[target] += drep
					last_rep[msg.author.id] = msg.created_at

		if msg.created_at-last_count.get(msg.author.id, datetime.datetime(2015, 5, 15, 0, 0, 0)) > datetime.timedelta(seconds=key.hail_cooldown):
			if msg.content.lower() in accepted_phrases:
				last_count[msg.author.id] = msg.created_at
				record[msg.author.id] += 1
		else:
			continue
예제 #6
0
파일: modtools.py 프로젝트: ntoskrnl4/arbys
			f"`{client.default_prefix}unlock`",
	"Arguments": "None",
	"Description": "Locks or unlocks the specified channel in case of a raid or general chaos. This command must be run in the target channel. Moderator-only channels cannot be locked."
}

purge_help = {
	"Usage": f"`{client.default_prefix}purge [n]`",
	"Arguments": "`n` - (Optional) Number of messages to delete, capped at 100. (default 25)",
	"Description": "Nukes some number of recent messages in a channel.",
}
client.long_help("lock", lock_help)
client.long_help("unlock", lock_help)
client.long_help("purge", purge_help)

try:
	yarc_role = client.get_guild(364480908528451584).get_role(639519325287350272)
except AttributeError:
	log.critical(f"YARC moderator role not found. Mod commands will raise an exception when run.")


@client.command(trigger="lock", aliases=["l"])
async def lock(command: str, message: discord.Message):
	if message.guild.id != 364480908528451584:
		if message.guild.id != 452274699641159683:
			# wrong guild
			await message.channel.send("Invalid server")
			return
	else:
		if yarc_role not in message.author.roles:
			# user is not a mod
			await __common__.failure(message)
예제 #7
0
async def command(command: str, message: discord.Message):
	try:
		try:
			u = await client.get_user_info(__common__.stripMentionsToID(command[6:]))
		except:
			isUser = False
		else:
			isUser = True

		s = client.get_guild(__common__.stripMentionsToID(command[6:]))
		if s is None:
			isServer = False
		else:
			isServer = True

		c = client.get_channel(__common__.stripMentionsToID(command[6:]))
		if c is None:
			isTextChannel = False
			isVoiceChannel = False
		else:
			if isinstance(c, discord.TextChannel):
				isTextChannel = True
				isVoiceChannel = False
			elif isinstance(c, discord.VoiceChannel):
				isTextChannel = False
				isVoiceChannel = True
			else:
				await message.channel.send("Invalid channel type - handling for this is not implemented. Sorry.")
				return

	except ValueError:
		u = message.author
		isUser = True
		s = message.guild
		isServer = True
		c = message.channel
		isTextChannel = True
		isVoiceChannel = False

	if isUser:
		user_embed = discord.Embed(title="User Information", description=f"Information about {u.mention}", color=0x3127b3)
		user_embed = user_embed.set_thumbnail(url=u.avatar_url_as(static_format="png", size=1024))
		user_embed = user_embed.add_field(name="Human-Friendly User ID", value=u.name+"#"+u.discriminator)
		user_embed = user_embed.add_field(name="User Avatar URL", value=u.avatar_url_as(static_format="png", size=1024))
		user_embed = user_embed.add_field(name="Raw User ID", value=u.id)
		user_embed = user_embed.add_field(name="Is Bot", value=u.bot)
		user_embed = user_embed.add_field(name="Account Creation Time", value=u.created_at)
		if message.guild.get_member(u.id) is not None:
			m = message.guild.get_member(u.id)
			roles = "\n".join([f"{x.name} ({x.id})" for x in m.roles][::-1])
			user_embed = user_embed.add_field(name="Roles in this server", value=roles, inline=False)
			user_embed = user_embed.add_field(name="User Nickname", value=m.display_name)
			user_embed = user_embed.add_field(name="Joined this server on", value=m.joined_at.__str__())

	if isServer:
		server_embed = discord.Embed(title="Server Information", description=f"Information about the server {s.name}", color=0xb368a2)
		server_embed = server_embed.set_thumbnail(url=s.icon_url)
		server_embed = server_embed.add_field(name="Name", value=s.name)
		server_embed = server_embed.add_field(name="Raw ID", value=s.id)
		icon = s.icon_url_as(format="png", size=1024)
		if icon == "":
			icon = "[no custom icon]"
		server_embed = server_embed.add_field(name="Icon URL", value=icon)
		server_embed = server_embed.add_field(name="Owner", value=f"{s.owner.name}#{s.owner.discriminator} ({s.owner.id})")
		server_embed = server_embed.add_field(name="Creation Time", value=s.created_at)
		server_embed = server_embed.add_field(name="Member Count", value=s.member_count)
		server_embed = server_embed.add_field(name="Role Count", value=len(s.roles))
		server_embed = server_embed.add_field(name="Emoji Count", value=len(s.emojis))
		server_embed = server_embed.add_field(name="Region", value=s.region)
		server_embed = server_embed.add_field(name="Is offline?", value=s.unavailable)
		server_embed = server_embed.add_field(name="Admin 2FA required?", value=s.mfa_level)
		server_embed = server_embed.add_field(name="Verification Level", value=s.verification_level)

	if isTextChannel:
		channel_embed = discord.Embed(title="Channel Information", description=f"Information about the text channel {c.mention}", color=0x8f44a2)
		channel_embed = channel_embed.add_field(name="Name", value=c.name)
		channel_embed = channel_embed.add_field(name="ID", value=c.id)
		channel_embed = channel_embed.add_field(name="Server", value=f"{c.guild.name} ({c.guild.id})")
		t = c.topic
		if t == "":
			t = "[none]"
		channel_embed = channel_embed.add_field(name="Topic", value=t, inline=False)
		channel_embed = channel_embed.add_field(name="Creation Time", value=c.created_at)

	if isVoiceChannel:
		channel_embed = discord.Embed(title="Channel Information", description=f"Information about the voice channel {c.name}", color=0x8f44a2)
		channel_embed = channel_embed.add_field(name="Name", value=c.name)
		channel_embed = channel_embed.add_field(name="ID", value=c.id)
		channel_embed = channel_embed.add_field(name="Server", value=f"{c.guild.name} ({c.guild.id})")
		channel_embed = channel_embed.add_field(name="Bitrate", value=c.bitrate)
		channel_embed = channel_embed.add_field(name="User Limit", value=c.user_limit)
		channel_embed = channel_embed.add_field(name="Creation Time", value=c.created_at)
		in_vc = "\n".join([f"{x.display_name} ({x.name}#{x.discriminator} - {x.id})" for x in c.members])
		if in_vc == "":
			in_vc = "[none]"
		channel_embed = channel_embed.add_field(name="Members Currently In Channel", value=in_vc)

	if isUser:
		await message.channel.send(embed=user_embed)
		await asyncio.sleep(0.05)

	if isServer:
		await message.channel.send(embed=server_embed)
		await asyncio.sleep(0.05)

	if isTextChannel or isVoiceChannel:
		await message.channel.send(embed=channel_embed)
		await asyncio.sleep(0.05)

	if not (isUser or isServer or (isTextChannel or isVoiceChannel)):  # if not a user, server, or channel:
		await message.channel.send(f"Unknown user, server, or channel with ID {command[6:]}. I might not be able to 'see' that object.")
	return
예제 #8
0
async def command(command: str, message: discord.Message):
    parts = command.split(" ")
    if len(parts) == 1:
        parts.append(str(message.author.id))
    try:
        u = await client.fetch_user(__common__.strip_to_id(parts[1]))
    except TypeError:
        await message.channel.send(
            "Invalid argument: integer ID or mentions are acceptable")
        return
    except:
        isUser = False
    else:
        isUser = True

    s = client.get_guild(__common__.strip_to_id(parts[1]))
    if s is None:
        isServer = False
    else:
        isServer = True

    c = client.get_channel(__common__.strip_to_id(parts[1]))
    if c is None:
        isTextChannel = False
        isVoiceChannel = False
    else:
        if isinstance(c, discord.TextChannel):
            isTextChannel = True
            isVoiceChannel = False
        elif isinstance(c, discord.VoiceChannel):
            isTextChannel = False
            isVoiceChannel = True
        else:
            await message.channel.send(
                "Invalid channel type - handling for this is not implemented. Sorry."
            )
            return

    if isUser and not "--status" in command:
        user_embed = discord.Embed(
            title="User Information",
            description=f"Information about {u.mention}",
            color=0x3127b3)
        user_embed = user_embed.set_thumbnail(url=u.avatar_url)
        user_embed = user_embed.add_field(name="Tag",
                                          value=u.name + "#" + u.discriminator)
        # user_embed = user_embed.add_field(name="Avatar URL", value=u.avatar_url_as(static_format="png", size=1024))
        if message.guild.get_member(u.id) is not None:
            m = message.guild.get_member(u.id)
            user_embed = user_embed.add_field(name="Nickname",
                                              value=m.display_name)
        user_embed = user_embed.add_field(name="Raw ID", value=u.id)
        # user_embed = user_embed.add_field(name="Is Bot", value=u.bot)
        ctime_str = f"{str(u.created_at)}\n({str(datetime.datetime.utcnow()-u.created_at)})"
        user_embed = user_embed.add_field(name="Account Creation Time",
                                          value=ctime_str)
        if get_any_member(u.id) is not None:
            m = get_any_member(u.id)
            user_embed = user_embed.add_field(
                name="Current Status",
                value=f"Apparent Status: {status_emoji(m.status)}\n"
                f"Desktop: {status_emoji(m.desktop_status)}\n"
                f"Web: {status_emoji(m.web_status)}\n"
                f"Mobile: {status_emoji(m.mobile_status)}\n",
                inline=True)
        if message.guild.get_member(u.id) is not None:
            m = message.guild.get_member(u.id)
            jtime_str = f"{str(m.joined_at)}\n({str(datetime.datetime.utcnow()-m.joined_at)})"
            user_embed = user_embed.add_field(name="Joined this server",
                                              value=jtime_str)
            roles = "\n".join([f"{x.name} ({x.id})" for x in m.roles][::-1])
            user_embed = user_embed.add_field(name="Roles in this server",
                                              value=roles,
                                              inline=False)
        user_embed = user_embed.set_footer(text=__common__.get_timestamp())

    if isUser and "--status" in command:
        if get_any_member(u.id) is not None:
            m = get_any_member(u.id)
        else:
            return await message.channel.send(
                "Cannot get status: I do not share any servers with this user (in order to get a user's status I must share a server with them)"
            )
        user_embed = discord.Embed(
            description=f"Apparent Status: {status_emoji(m.status)}\n"
            f"Desktop: {status_emoji(m.desktop_status)}\n"
            f"Web: {status_emoji(m.web_status)}\n"
            f"Mobile: {status_emoji(m.mobile_status)}\n"
            f"Is on mobile? {m.is_on_mobile()}", )
        user_embed = user_embed.set_author(icon_url=m.avatar_url_as(
            format="png", size=128),
                                           name=f"{m.name}#{m.discriminator}")
        user_embed = user_embed.set_footer(text=__common__.get_timestamp())

    if isServer:
        server_embed = discord.Embed(title="Server Information",
                                     color=0xb368a2)
        server_embed = server_embed.add_field(name="Name", value=s.name)
        server_embed = server_embed.add_field(name="Raw ID", value=s.id)
        icon = s.icon_url_as(format="png", size=1024)
        if not icon:  # Used to be != "" before icon was a discord.Asset, credit to eyyyyyy for finding/fixing this
            icon = "[no custom icon]"
            server_embed = server_embed.set_thumbnail(url=s.icon_url)
        server_embed = server_embed.add_field(name="Icon URL", value=icon)
        server_embed = server_embed.add_field(
            name="Owner",
            value=f"{s.owner.name}#{s.owner.discriminator}\nID {s.owner.id}")
        server_embed = server_embed.add_field(name="Member Count",
                                              value=s.member_count)
        server_embed = server_embed.add_field(name="Role Count",
                                              value=len(s.roles))
        server_embed = server_embed.add_field(name="Emoji Count",
                                              value=len(s.emojis))
        server_embed = server_embed.add_field(name="Creation Time",
                                              value=s.created_at)
        server_embed = server_embed.add_field(name="Region", value=s.region)
        server_embed = server_embed.add_field(name="Is offline?",
                                              value=s.unavailable)
        server_embed = server_embed.add_field(name="Admin 2FA required?",
                                              value=bool(s.mfa_level))
        server_embed = server_embed.add_field(name="Verification Level",
                                              value=s.verification_level)
        server_embed = server_embed.set_footer(text=__common__.get_timestamp())

    if isTextChannel:
        channel_embed = discord.Embed(
            title="Channel Information",
            description=f"Information about the text channel {c.mention}",
            color=0x8f44a2)
        channel_embed = channel_embed.add_field(name="Name", value=c.name)
        channel_embed = channel_embed.add_field(name="ID", value=c.id)
        channel_embed = channel_embed.add_field(
            name="Server", value=f"{c.guild.name} ({c.guild.id})")
        t = c.topic
        if t == "":
            t = "[none]"
        channel_embed = channel_embed.add_field(name="Topic",
                                                value=t,
                                                inline=False)
        channel_embed = channel_embed.add_field(name="Creation Time",
                                                value=c.created_at)

    if isVoiceChannel:
        channel_embed = discord.Embed(
            title="Channel Information",
            description=f"Information about the voice channel {c.name}",
            color=0x8f44a2)
        channel_embed = channel_embed.add_field(name="Name", value=c.name)
        channel_embed = channel_embed.add_field(name="ID", value=c.id)
        channel_embed = channel_embed.add_field(
            name="Server", value=f"{c.guild.name} ({c.guild.id})")
        channel_embed = channel_embed.add_field(name="Bitrate",
                                                value=c.bitrate)
        channel_embed = channel_embed.add_field(name="User Limit",
                                                value=c.user_limit)
        channel_embed = channel_embed.add_field(name="Creation Time",
                                                value=c.created_at)
        in_vc = "\n".join([
            f"{x.display_name} ({x.name}#{x.discriminator} - {x.id})"
            for x in c.members
        ])
        if in_vc == "":
            in_vc = "[none]"
        channel_embed = channel_embed.add_field(
            name="Members Currently In Channel", value=in_vc)

    if isUser:
        await message.channel.send(embed=user_embed)
        await asyncio.sleep(0.05)

    if isServer:
        await message.channel.send(embed=server_embed)
        await asyncio.sleep(0.05)

    if isTextChannel or isVoiceChannel:
        channel_embed = channel_embed.set_footer(
            text=__common__.get_timestamp())
        await message.channel.send(embed=channel_embed)
        await asyncio.sleep(0.05)

    if not (isUser or isServer or
            (isTextChannel
             or isVoiceChannel)):  # if not a user, server, or channel:
        await message.channel.send(
            f"Unknown user, server, or channel with ID {parts[1]}. I might not be able to 'see' that object."
        )
    return
예제 #9
0
    "run in the target channel. Moderator-only channels cannot be locked. "
}

purge_help = {
    "Usage": f"`{client.default_prefix}purge [n]`",
    "Arguments":
    "`n` - (Optional) Number of messages to delete, capped at 100. (default 25)",
    "Description": "Nukes some number of recent messages in a channel.",
}
client.long_help("lock", lock_help)
client.long_help("unlock", lock_help)
client.long_help("purge", purge_help)

admin_role = None
if client.is_ready():
    admin_role = client.get_guild(458765854624972811).get_role(
        458767248367157278), client.get_guild(458765854624972811).get_role(
            882726753074819124)


@client.ready
async def set_mod_role():
    global admin_role
    try:
        admin_role = admin_role = client.get_guild(
            458765854624972811).get_role(458767248367157278), client.get_guild(
                458765854624972811).get_role(882726753074819124)
    except AttributeError:
        log.critical(f"FAU mod role not found, oof")


@client.command(trigger="lock", aliases=["l"])