async def on_message(msg): # ignore bots if msg.author.bot: return # the actual arguments args = msg.content[len(auth.prefix):].strip().split(' ') # get the command cmd = args.pop(0).lower() # used for shortening code c = msg.channel g = msg.guild m = msg.author try: conf = db.fetch(server_config, {'guild': g.id}).fetchone() except AttributeError: db.insert(server_config, {'guild': g.id}) # extremely inefficient system but idgaf if not 'tag' in cmd: if (tagss := db.fetch(tags, {'guild': msg.guild.id})): tagls = tagss.fetchall() if not conf.tag_require_command: if conf.tag_search_all: found = [x.content for x in [x for x in tagls if msg.content.find(x.name) != -1]] else: found = [x.content for x in [x for x in tagls if msg.content == x.name]] if len(found) > 0: return await msg.channel.send(found[0])
async def on_member_join(m): mgc = db.fetch(server_config, {'guild': m.guild.id}).fetchone() if mgc.mute_evasion: muted = conn.execute(muted_members.select().where(muted_members.c.unmute_after <= int(time.time())).where(muted_members.c.id == m.id)).fetchone() if muted: await m.add_roles(db.fetch(muted_roles, {'guild': m.guild.id}), f'Mute evasion; added {mgc.mute_evasion_time} hours to mute time.') db.update(muted_members, {'id': m.id}, {'unmute_after': calendar.timegm((muted.unmute_after + timedelta(hours=mgc.mute_evasion_time).timetuple()))}) try: await m.send(f'Looks like you were mute evading in {m.guild}.\nYour mute time has been extended by {mgc.mute_evasion_time} hours. If you believe this is in error, please contact the admins/mods of the server.') except: pass
async def search(): """Searches through muted members and unmutes them if their mute time is up.""" # this uses raw requests to prevent aiohttp from yelling at me mems = conn.execute(muted_members.select().where( muted_members.c.unmute_after <= int(time.time()))).fetchall() for m in mems: gid = m[1] mid = m[0] try: roles = req(f'guilds/{gid}/members/{mid}', {}, 'get').json()['roles'] except KeyError as e: print(e) continue rid = db.fetch(muted_roles, {'guild': gid}).fetchone().id try: del roles[roles.index(str(rid))] except: pass rm = req(f'guilds/{gid}/members/{mid}', json.dumps({'roles': roles}), 'patch') if rm.status_code == 204: db.delete(muted_members, {'id': mid, 'guild': gid}) else: return try: cid = req('users/@me/channels', json.dumps({'recipient_id': mid}), 'post').json()['id'] gname = req(f'guilds/{gid}', {}, 'get').json()['name'] req(f'channels/{cid}/messages', { 'content': f'You have been automatically unmuted in {gname}.' }, 'post') except: pass
async def run(**env): for _, a in enumerate(env): globals().update({a: env.get(a)}) fetched = db.fetch(roles, {'guild': g.id}) if fetched: row = fetched.fetchone() if row.id == role.id: return await c.send('This role is already the muted role.') try: db.update(roles, {'guild': g.id}, {'id': args[0]}) for x in g.categories: await x.edit( overwrites={ role: discord.PermissionOverwrite(send_messages=False, add_reactions=False) }) return await c.send( f'Successfully set muted role to {role.mention}.') except Exception as e: print(e) await c.send(f'Error while setting muted role:\n{e}') else: try: db.insert(roles, {'id': args[0], 'guild': g.id}) return await c.send( f'Successfully set muted role to {role.mention}.') except Exception as e: print(e) return await c.send(f'Error while setting muted role:\n{e}')
async def run(**env): for _, a in enumerate(env): globals().update({a: env.get(a)}) result = db.fetch(tags, {'guild': g.id}) if not result: return await c.send('No tags exist on this server.') tags_str = '' fieldnum = 0 emb = discord.Embed() emb.title = f'All tags in server {g}' emb.description = 'Use ~~taginfo (tag name) for info on these tags.' # basically gets all the tags and formats them to fit on an embed for row in result: if len(tags_str) > 1000: if fieldnum == 0: emb.add_field(name='Tags', value=tags_str, inline=False) else: emb.add_field(name='Continued', value=tags_str, inline=False) fieldnum += 1 tags_str = '' tags_str += f'{row.name}\n' if fieldnum == 0: emb.add_field(name='Tags', value=tags_str, inline=False) else: emb.add_field(name='Continued', value=tags_str, inline=False) await c.send(embed=emb)
async def run(**env): for _, a in enumerate(env): globals().update({a: env.get(a)}) # checks the muted role result = db.fetch(roles, {'guild': g.id}) if not result: return await c.send( 'No muted role is set! Please set one with `setmuted`.') role = result.fetchone() muted_role = g.get_role(role.id) if g.me.top_role < muted_role: return await c.send( 'I am at a lower level on the hierarchy than the muted role.') try: await checks.roles(m, mem, g, c) except: return # makes sure they aren't already muted if muted_role in mem.roles: return await c.send('That member is already muted.') try: # add the muted role to the member await mem.add_roles(muted_role, reason=reason) db.insert(mems, { 'id': mem.id, 'guild': g.id, 'unmute_after': get_future(time) }) await c.send( f'Successfully muted {mem} for {time} hours. Reason: {reason}') if conf.mute_dm: try: await mem.send( conf.mute_dm_message.format(MEM=mem, GUILD=g, MOD=m, TIME=time, REASON=reason)) except: pass except Exception as e: await c.send(f'Error while muting member: {e}')
async def run(**env): for _, a in enumerate(env): globals().update({a: env.get(a)}) opt = db.fetch(server_config, {'guild': g.id}).fetchone() conf_emb = discord.Embed() to_upd = {} setbase(conf_emb, 'Server Configuration', 'Welcome to the interactive server configuration module!\nPlease choose the module to enter by typing its name.') addfield(conf_emb, 'Commands', 'Individual command configuration.') addfield(conf_emb, 'Other', 'General configuration settings.') conf_emb.set_footer(text='Type "back" to go back at any time.') emb = await c.send(embed=conf_emb) await main(client, m, emb, conf_emb, opt, to_upd)
async def run(**env): for _, a in enumerate(env): globals().update({a: env.get(a)}) result = db.fetch(roles, {'guild': g.id}) if not result: return await c.send( 'No muted role is set! Please set one with `setmuted`.') role = result.fetchone() muted_role = g.get_role(id=role.id) if g.me.top_role < muted_role: return await c.send( 'I am at a lower level on the hierarchy than the muted role.') try: await checks.roles(m, mem, g, c) except: return if not muted_role in mem.roles: return await c.send('This member is not muted.') try: await mem.remove_roles(muted_role, reason=reason) db.delete(mems, {'id': mem.id, 'guild': g.id}) await c.send(f'Successfully unmuted {mem}.\nReason: {reason}') if conf.mute_dm: try: await mem.send( conf.mute_dm_message.format(MEM=mem, GUILD=g, MOD=m, REASON=reason)) except: pass except Exception as e: await c.send(f'Error while unmuting member: {e}')
from tables import tags name = 'taginfo' names = ['taginfo'] desc = 'Get info on a tag in the server.' examples = ['example'] notes = 'Similarly to the `tag` command, tags are specific to servers. '\ 'This command gives you the tag name, content, author, and creation date.' reqargs = ['args', 'client', 'g', 'c'] cargs = [ { 'name': 'tag name', 'aname': 'tag', 'optional': False, 'excarg': 'g', 'check': lambda a, g: db.fetch(tags, {'name': a, 'guild': g.id}), 'errmsg': 'That tag doesn\'t exist in this server.' } ] async def run(**env): for _, a in enumerate(env): globals().update({a: env.get(a)}) tagf = tag.fetchone() emb = discord.Embed() emb.title = f'Tag {tagf.name}' emb.description = tagf.content
async def on_channel_create(c): if c.type == discord.ChannelType.category or not c.category: roles = db.fetch(muted_roles, {'guild': g.id}) if roles: role = c.guild.get_role(roles.fetchone()) await c.edit(overwrites={role: discord.PermissionOverwrite(send_messages=False, add_reactions=False)})