def predicate(ctx): if ctx.guild: settings = mongo.settings(ctx.guild) admin_roles = settings.get("admin_roles").split(";") return (set([str(i.id) for i in ctx.author.roles]).__and__( set([str(x) for x in admin_roles])) != set() or ctx.author.guild_permissions.administrator) else: return False
async def show(self, ctx): embedVar = discord.Embed(title="", inline=False) self.bot_member = ctx.guild.get_member(self.bot.user.id) embedVar.set_author( name=f"{self.bot_member.display_name} | {ctx.command}", icon_url=str(self.bot_member.avatar_url_as(size=512)), ) settings = mongo.settings(ctx.guild) settingkeys = [] for setting in settings.print_all(): embedVar.add_field( name=setting["name"] + " = " + str(setting["value"]), value=setting["Description"], inline=False, ) await ctx.reply(embed=embedVar)
async def add_admin(self, ctx, *roles: discord.Role): settings = mongo.settings(ctx.guild) admin_roles = settings.get("admin_roles") if admin_roles == "": admin_roles = [] else: admin_roles = admin_roles.split(";") new_admin_roles = [ str(role.id) for role in roles if role not in admin_roles ] new_roles = admin_roles + new_admin_roles print(new_roles) role_string = ";".join(new_roles) print(role_string) command_args = ["admin_roles", role_string] await ctx.invoke(self.bot.get_command("set"), *command_args)
async def on_member_update( self, before: discord.Member, after: discord.Member ) -> bool: """ If role is mute then log mute Else log the role change """ try: role = Diff(before.roles, after.roles)[0] except IndexError: return True self.settings = mongo.settings(after.guild) muted_role = self.settings.get("muted_role") if str(role.id) == str(muted_role): action = "Toggled_Mute" role = None if str(muted_role) in [str(i.id) for i in after.roles]: action_pretty = "Muted" else: action_pretty = "Unmuted" else: action = "Toggled_Role" if role in after.roles: action_pretty = "Gave Role" else: action_pretty = "Removed Role" log_action = discord.AuditLogAction.member_role_update guild = after.guild entry = await self.log_handlers.get_audit_log_event( log_action=log_action, guild=guild, user=after, action=action, ) return await self.log_handlers.log_event( action=action, entry=entry, role=role, guild=guild, action_pretty=action_pretty, )
async def lookup(self, ctx, setting): embedVar = discord.Embed(title="", inline=False) self.bot_member = ctx.guild.get_member(self.bot.user.id) embedVar.set_author( name=f"{self.bot_member.display_name} | {ctx.command}", icon_url=str(self.bot_member.avatar_url_as(size=512)), ) settings = mongo.settings(ctx.guild) settingkeys = [x["name"] for x in settings.print_all()] print(settingkeys) matches = get_close_matches(setting, settingkeys) for match in matches: embedVar.add_field( name=match + " = " + str(settings.get(match)), value=settings.get_description(setting), inline=False, ) return await ctx.reply(embed=embedVar)
async def on_voice_state_update( self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState, ) -> bool: if before.mute != after.mute: action = "Toggled_VC_Mute" if before.mute is False: action_pretty = "VC Muted" elif before.mute is True: action_pretty = "VC Unmute" log_action = discord.AuditLogAction.member_update elif before.deaf != after.deaf: action = "Toggled_VC_deaf" if before.deaf is False: action_pretty = "VC deafened" elif before.deaf is True: action_pretty = "VC undeafened" log_action = discord.AuditLogAction.member_update else: return True self.settings = mongo.settings(member.guild) entry = await self.log_handlers.get_audit_log_event( log_action=log_action, guild=member.guild, action=action ) if entry is None: return False return await self.log_handlers.log_event( action=action, entry=entry, guild=member.guild, target=member, action_pretty=action_pretty, )
async def set(self, ctx, setting, value, *desc): await ctx.channel.trigger_typing() embedVar = discord.Embed(title="", inline=False) self.bot_member = ctx.guild.get_member(self.bot.user.id) settings = mongo.settings(ctx.guild) update = settings.update(setting, value, *desc) extensions = list(self.bot.extensions.keys()) for extension in extensions: self.bot.reload_extension(extension) embedVar.set_author( name=f"{self.bot_member.display_name} | {ctx.command}", icon_url=str(self.bot_member.avatar_url_as(size=512)), ) if update: embedVar.add_field(name="Old", value=update["oldkey"], inline=True) embedVar.add_field(name="New", value=update["newkey"], inline=True) embedVar.add_field(name="Description", value=settings.get_description(setting)) m1 = await ctx.reply(embed=embedVar, content="reloaded") else: settings.create(setting, value, *desc) m1 = await ctx.reply( f"{setting} didn't have any results so i created a new one") print(type(self.bot)) m2 = await self.admin_commands.lookup(ctx, setting) await self.admin_commands.reload(ctx) print(ctx.command) if str(ctx.command) == "set_log": await ctx.channel.trigger_typing() await asyncio.sleep(10) await ctx.message.delete() await m1.delete() try: await m2.delete() except UnboundLocalError: pass
import discord from discord.ext import commands import mongo settings = mongo.settings() command_channel_id = settings.get('command_channel_id') def setup(bot): bot.add_cog(search(bot)) class search(commands.Cog): def __init__(self, bot): self.bot = bot self._last_member = None @commands.has_permissions(administrator=True) @commands.command( name='ticket_search', help='Enter a ticket-name (E.G ticket-1) aand get a full transcript') async def ticket_search(self, ctx, TicketName): admin_log = await self.bot.fetch_channel(command_channel_id) count = 0 embedVar = discord.Embed(title=TicketName, inline=False) for message in mongo.search.get_messages_by_tickets(TicketName): if count > 25: await admin_log.send(embed=embedVar) count = 1 embedVar = discord.Embed(title=TicketName + '(cont)', inline=False) if len(message['content']) > 1000:
def log_location(self, log_item: str, guild: discord.Guild) -> int: self.settings = mongo.settings(guild) return self.settings.get(log_item) or self.settings.get("log_channel_id")
async def get_pre(bot, message): if message.guild is not None: settings = mongo.settings(message.guild) prefix = settings.get("prefix") return prefix
setting = client['settingdb'] settingcol = setting['settings'] # Build a basic dictionary # client.drop_database(setting) # Insert the dictionary into Mongo # settingcol.insert_one({ # "prefix" : "&", # "catagory_id": "797996052074201088", # "command_channel_id" : "797996052074201088" # }) # print(setting.list_collection_names()) #collection.update_one({"count" : {}}, { '$inc': { 'count': 1 }}) counts = settingcol.find({}, {"addresses": {"$slice": [0, 1]}, '_id': 0}) for key in counts: print(key) print(mongo.settings().update('test', 'test2', 'test3')) for key in counts: print(key) #print(db.count()) #client.drop_database(db) #client.drop_database('tickets') #client.drop_database('userid') #client.drop_database('db')