async def echo(self, ctx, channel: nextcord.TextChannel, *, message: str): f.log( f"{ctx.author} in '{ctx.guild.name}' to #{channel} {'('+channel.guild.name+')' if channel.guild.name != ctx.guild.name else ''} echoed '{message}'" ) await channel.send(message) await ctx.message.add_reaction(tt.e.check)
async def toggle(self, ctx, *, x=None): if x == None: toggles = f.data(tt.misc, 'misc', 'disabled')['disabled'] await ctx.send( f"```disabled commands:\n{tt.n.join(toggles) if len(toggles) > 0 else 'n/a'}\n\ndisabled cogs:\n{tt.n.join([cog for cog in tt.cogs if cog not in tt.loaded]) if sorted(tt.cogs) != sorted(tt.loaded) else 'n/a'}```" ) return if x in tt.cogs: try: self.bot.load_extension('cogs.' + x) await ctx.message.add_reaction(tt.e.check) tt.loaded.append(x) f.log('loaded ' + x) except commands.ExtensionAlreadyLoaded: self.bot.unload_extension('cogs.' + x) await ctx.message.add_reaction(tt.e.check) tt.loaded.remove(x) f.log('unloaded ' + x) except Exception as error: raise (error) return else: command = self.bot.get_command(x) if not command or ctx.command == command: await ctx.send(tt.x + f"invalid command or cog provided!") return command.enabled = not command.enabled f._list(tt.misc, 'misc', 'disabled', [command.qualified_name], 'add' if not command.enabled else 'remove') await ctx.message.add_reaction(tt.e.check)
async def tag_force_remove(self, ctx, tag: tname): tagdata = self.db.find_one({'_id': tag}, {'owner': 1}) if not await self.tag_check(tag, tagdata, ctx): return self.db.delete_one({'_id': tag}) await ctx.send(tt.y + f"forcefully deleted the tag **{tag}**!") f.log(f"{ctx.author} forcefully deleted '{tag}'", '[TAGS]')
async def massnick(self, ctx, *, param:str): await ctx.trigger_typing() stupid = {'change':['changing','changed'],'clear':['clearing','cleared'],'undo':['reverting','reverted']} try: if len(param) > 32: await ctx.send(tt.w+"maximum of 32 characters for nicknames!") return if ctx.guild.id in self.mn_in_progress: if param == 'cancel': self.mn_in_progress.remove(ctx.guild.id) return await ctx.send(tt.w+"there is already a massnick in progress!") return elif param == 'cancel': await ctx.send(tt.x+"no massnick in progress!") return nicknames_list = f.data(tt.storage, ctx.guild.id, 'nicknames', {'nicknames':{}})['nicknames'] if param == 'undo': if 'users' not in nicknames_list or len(nicknames_list['users']) == 0: await ctx.send(tt.x+"no nickname history found for this server!") return nickname = param elif param == 'clear': nickname = None else: nickname = param param = 'change' mn_users = [member for member in ctx.guild.members if not member.bot and member.top_role < ctx.guild.me.top_role and member.nick != nickname] if len(mn_users) == 0: await ctx.send(tt.w+"role hierarchy is preventing me from nicknaming anyone!") return self.mn_in_progress.append(ctx.guild.id) await ctx.send(tt.h+f"attempting to {param} {len(mn_users)} of {ctx.guild.member_count} nicknames, please wait...") f.log(f"{stupid[param][0]} {len(mn_users)} nicknames in {ctx.guild.name}", '[MASSNICK]') mn_changed = 0 self.mn_storage[ctx.guild.id] = {} async with ctx.channel.typing(): for member in mn_users: if ctx.guild.id not in self.mn_in_progress: await ctx.send(tt.y+"massnick cancelled!") break if param != 'undo': self.mn_storage[ctx.guild.id].update({str(member.id):member.nick}) elif member.nick == nicknames_list['lastnick'] and str(member.id) in nicknames_list['users']: nickname = nicknames_list['users'][str(member.id)] try: await member.edit(nick=nickname) mn_changed += 1 except: continue f._set(tt.storage, ctx.guild.id, {"$set":{"nicknames.users":self.mn_storage[ctx.guild.id],"nicknames.lastnick":nickname if param != 'undo' else 'undo'}}) self.mn_in_progress.remove(ctx.guild.id) await ctx.send(tt.y+f"`{mn_changed}/{len(mn_users)}` nicknames successfully {stupid[param][1]}!") f.log(f"{stupid[param][1]} {mn_changed}/{len(mn_users)} nicknames in {ctx.guild.name}", '[MASSNICK]') except Exception as error: if ctx.guild.id in self.mn_in_progress: self.mn_in_progress.remove(ctx.guild.id) raise(error)
async def on_ready(): f.log('ready!') await bot.change_presence(status=tt.presence.default[1], activity=nextcord.Activity(type=tt.presence.default[2],name=tt.presence.default[0])) tt.e.upvote = bot.get_emoji(tt.e.upvote) tt.e.downvote = bot.get_emoji(tt.e.downvote) if not tt.testing: tt.misc.update_one({'_id':'misc'}, {"$set":{"guilds":[guild.id for guild in bot.guilds]}}, upsert=True) print(f"\n ___/-\___ Online\n |---------| {bot.user.name}#{bot.user.discriminator} ({bot.user.id})\n | | | | | _ _ _ _ \n | | | | | | |_ _ __ __ _ ___| |__ | |__ ___ | |_ \n | | | | | | __| '__/ _` / __| '_ \| '_ \ / _ \| __|\n | | | | | | |_| | | (_| \__ \ | | | |_) | (_) | |_ \n |_______| \__|_| \__,_|___/_| |_|_.__/ \___/ \__|\n")
async def report(self, ctx, *, report:str): await ctx.trigger_typing() if len(report) > 1000: ctx.command.reset_cooldown() await ctx.send(tt.w+"your report is too long! (max 1000 characters)") return report = f"report from {ctx.author} in '{ctx.guild.name}'\n\"{report}\" {' '.join([a.url for a in ctx.message.attachments])}" f.log(report, '[REPORT]') await self.bot.get_user(tt.admins[0]).send(report) await ctx.send(tt.y+"your report has been submitted!")
async def reload(self, ctx, cog): if cog not in tt.cogs: await ctx.send(tt.x + f"{cog} is not a valid cog!") return if cog in tt.loaded: tt.loaded.remove(cog) self.bot.reload_extension('cogs.' + cog) if cog not in tt.loaded: tt.loaded.append(cog) await ctx.message.add_reaction(tt.e.check) f.log('reloaded ' + cog)
async def on_command_error(self, ctx, error): error = getattr(error, 'original', error) if isinstance(error, commands.CommandNotFound): return elif isinstance(error, commands.UserInputError): ctx.command.reset_cooldown(ctx) command = ctx.command.qualified_name cog = ctx.command.cog.qualified_name await ctx.send(tt.w + f"invalid command parameters provided!" + ( f'\n{tt.s}{tt.s}`{ctx.prefix if str(self.bot.user.id) not in ctx.prefix else "@eli bot "}{cmds._c_[cog][1][command][0]}`' if cog in cmds._c_ and command in cmds._c_[cog][1] else '')) elif isinstance(error, commands.DisabledCommand): await ctx.send( tt.x + f"this command is currently disabled for maintenance!") elif isinstance(error, commands.NoPrivateMessage): await ctx.send(tt.x + "this command can only be used in servers!") elif isinstance(error, commands.BotMissingPermissions): await ctx.send( tt.x + f"i need {format_perms(error)} to use this command!") elif isinstance(error, commands.MissingPermissions): await ctx.send( tt.x + f"you need {format_perms(error)} to use this command!") elif isinstance(error, commands.CommandOnCooldown): await ctx.send( tt.h + f"please wait `{f.seconds(math.ceil(error.retry_after))}` before using this command again!" ) elif isinstance(error, checks.GuildCommandDisabled): await ctx.send(tt.x + "this command is disabled in this server!") elif isinstance(error, commands.CheckFailure): await ctx.send(tt.x + "you do not have permission to use this command!") else: f.log( f"Ignoring exception in command '{ctx.command.qualified_name}':\n" + ''.join( traceback.format_exception(type(error), error, error.__traceback__)), False, ['temp/error.txt', 'w'], tt.ansi.red + tt.ansi.bold) await ctx.send( tt.w + f"i ran into an error running this command! the error log is attached, please report it with 't!report'!\n**note: eli bot is currently in a testing stage for nextcord.py 2.0; if you experience any errors, i highly encourage you report them!**", file=nextcord.File('temp/error.txt'))
async def tag_transfer(self, ctx, tag: tname, user: nextcord.Member): tagdata = self.db.find_one({'_id': tag}, {'owner': 1}) if not await self.tag_check(tag, tagdata, ctx): return self.db.update_one({'_id': tag}, {"$set": { "owner": user.id }}, upsert=False) await ctx.send( tt.y + f"transferred ownership of the tag **{tag}** to **{user}**!") f.log(f"transferred {tag}' ({ctx.author} -> {user})", '[TAGS]')
async def presence(self, ctx, *, presence: str): x = tt.presence.default for y, z in enumerate(presence.split(';')): x[y] = z if x[1] not in tt.presence.status or x[2] not in tt.presence.activity: await ctx.send( tt.x + f"invalid format! (text;{'/'.join(tt.presence.status)};{'/'.join(tt.presence.activity)})" ) return await self.bot.change_presence(status=tt.presence.status[x[1]], activity=nextcord.Activity( type=tt.presence.activity[x[2]], name=x[0])) f.log(f"{ctx.author} set presence to {x[1]}, {x[2]} '{x[0]}'") await ctx.message.add_reaction(tt.e.check)
async def tag_edit(self, ctx, tag: tname, *, tag_content: str): tagdata = self.db.find_one({'_id': tag}, {'owner': 1, 'content': 1}) if not await self.tag_check(tag, tagdata, ctx): return content = await self.manage_content(tag, tag_content, ctx) if not content: return self.db.update_one({'_id': tag}, { "$set": { "content": content, "date": datetime.datetime.utcnow().timestamp() } }, upsert=True) await ctx.send(tt.y + f"updated the tag **{tag}**!") f.log(f"{ctx.author} updated '{tag}' ({content})", '[TAGS]')
async def blacklist(self, ctx, user: nextcord.User = None): if user == None: _list = '' for id in tt.blacklist: _user = self.bot.get_user(id) _list += f" - {_user} ({_user.id})\n" await ctx.send(f"```blacklisted users:\n{_list}```") elif user.id in tt.admins: await ctx.send(tt.x + "bot admins cannot be blacklisted!") return elif user.id not in tt.blacklist: tt.blacklist.append(user.id) f._list(tt.misc, 'misc', 'blacklist', [user.id], 'add') msg = f"blacklisted {user}" else: tt.blacklist.remove(user.id) f._list(tt.misc, 'misc', 'blacklist', [user.id], 'remove') msg = f"unblacklisted {user}" f.log(f"{ctx.author} {msg}") await ctx.send(tt.y + msg + '!')
async def tag_create(self, ctx, tag: tname, *, tag_content: str): tagdata = self.db.find_one({'_id': tag}, {'_id': 1}) if tagdata != None: await ctx.channel.send(tt.x + f"the provided tag already exists!") return if not await self.tag_check(tag, tagdata, ctx): return content = await self.manage_content(tag, tag_content, ctx) if not content: return self.db.update_one({'_id': tag}, { "$set": { 'content': tag_content, 'owner': ctx.author.id, 'date': datetime.datetime.utcnow().timestamp() } }, upsert=True) await ctx.send(tt.y + f"created the tag **{tag}**!") f.log(f"{ctx.author} created '{tag}' ({content})", '[TAGS]')
async def leave(self, ctx): f.log(f"{ctx.guild.author} removed from '{ctx.guild.name}'") await ctx.message.add_reaction(tt.e.check) await ctx.guild.leave()
async def restart(self, ctx): f.log(f"restarted by {ctx.author}") await ctx.message.add_reaction(tt.e.check) await os.execv(sys.executable, ['python'] + sys.argv)
async def say(self, ctx, *, message: str): f.log(f"{ctx.author} in '{ctx.guild.name}' used say '{message}'") await ctx.send(message)