From 4b60a9d5b385ee7c67f6cba8d5750aad894f9fb8 Mon Sep 17 00:00:00 2001 From: TheKaushikGoswami Date: Tue, 29 Jun 2021 14:36:14 +0530 Subject: [PATCH] Patch-2.2 See v2.2 for more info! --- cogs/api_cmd.py | 19 +++++- cogs/fun.py | 2 +- cogs/help.py | 2 +- cogs/mod.py | 113 ++++++++++++++++++-------------- cogs/nqn.py | 166 +++++++++++++++++++++++------------------------- cogs/owner.py | 5 +- cogs/say.py | 4 +- cogs/utility.py | 71 +++++++++++++++++++-- 8 files changed, 240 insertions(+), 142 deletions(-) diff --git a/cogs/api_cmd.py b/cogs/api_cmd.py index 37fa61b..783c298 100644 --- a/cogs/api_cmd.py +++ b/cogs/api_cmd.py @@ -1,3 +1,4 @@ +import io import discord import praw from discord.ext import commands, tasks @@ -379,9 +380,25 @@ async def joke(self, ctx): embed.set_footer(text='Prompted by {}'.format(ctx.author), icon_url=ctx.author.avatar_url) await ctx.send(embed=embed) +#triggered pic CMD + + @commands.command() + async def triggered(self, ctx, member: discord.Member = None): + if member == None: + member = ctx.author + await ctx.trigger_typing() + async with aiohttp.ClientSession() as session: + async with session.get(f'https://some-random-api.ml/canvas/triggered?avatar={member.avatar_url_as(format="png")}') as af: + if 300 > af.status >= 200: + fp = io.BytesIO (await af.read()) + file = discord.File(fp, "triggered.png") + em = discord.Embed(title="", color=ctx.author.color) + em.set_image(url="attachment://triggered.png") + await ctx.send(embed=em, file=file) + def setup(bot): bot.add_cog(Api(bot)) print("Api cog is Working!") -#👍: {ups} | 👎: {downs} \ No newline at end of file +#👍: {ups} | 👎: {downs} diff --git a/cogs/fun.py b/cogs/fun.py index 58e7252..ca50f46 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -523,4 +523,4 @@ async def kill(self, ctx, *, user: discord.Member = None): def setup(bot): bot.add_cog(Fun(bot)) - print("Fun Cog is Loaded!") \ No newline at end of file + print("Fun Cog is Loaded!") diff --git a/cogs/help.py b/cogs/help.py index 97c7be9..1a62d32 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -329,4 +329,4 @@ async def embedtest(self, ctx): def setup(Bot): Bot.add_cog(SPIKE(Bot)) - print("Help cog is working.") \ No newline at end of file + print("Help cog is working.") diff --git a/cogs/mod.py b/cogs/mod.py index a75564c..3ecbf06 100644 --- a/cogs/mod.py +++ b/cogs/mod.py @@ -1,5 +1,6 @@ import discord from discord import guild +from discord.errors import HTTPException from discord.ext import commands from discord import User import datetime @@ -10,22 +11,6 @@ from discord.ext.commands.core import check -time_regex = re.compile("(?:(\d{1,5})(h|s|m|d))+?") -time_dict = {"h":3600, "s":1, "m":60, "d":86400} - -class TimeConverter(commands.Converter): - async def convert(self, ctx, argument): - args = argument.lower() - matches = re.findall(time_regex, args) - time = 0 - for v, k in matches: - try: - time += time_dict[k]*float(v) - except KeyError: - raise commands.BadArgument("{} is an invalid time-key! h/m/s/d are valid!".format(k)) - except ValueError: - raise commands.BadArgument("{} is not a number!".format(v)) - return time class Mod(commands.Cog, name='Mod'): @@ -52,7 +37,7 @@ async def nick(self, ctx, member: discord.Member, *, nick): async def kick(self, ctx, user : discord.Member, *, reason = None): """Kicks a user from the server.""" if user == ctx.guild.owner: - return await ctx.send(f'** You are not cool enough to mute that person.**') + return await ctx.send(f'** You are not cool enough to kick that person.**') if ctx.author == user: await ctx.send("You cannot kick yourself.") return @@ -123,38 +108,69 @@ async def unban(self, ctx, *, member): #mute CMD @commands.command(aliases=['tempmute']) - @commands.has_permissions(manage_messages=True) - async def mute(self, ctx, member: discord.User=None, time:TimeConverter = None, *, reason=None): - if member in ctx.guild.members: + async def mute(self, ctx, member: discord.Member=None, time=None, *, reason=None): + if not member: + await ctx.send("You must mention a member to mute!") + + if member == ctx.guild.owner: + return await ctx.send(f'** You are not cool enough to mute that person.**') + + if ctx.message.author.top_role <= member.top_role: + await ctx.send(f"** You are not cool enough to mute that person.**") + return + + elif not time: + await ctx.send("You must mention a time!") + + else: + if not reason: + reason="No reason given" + #Now timed mute manipulation - if member == ctx.guild.owner: - return await ctx.send(f'** You are not cool enough to mute that person.**') - if ctx.message.author.top_role <= member.top_role: - await ctx.send(f"** You are not cool enough to mute that person.**") + try: + seconds = int(time[:-1]) #Gets the numbers from the time argument, start to -1 + duration = time[-1] #Gets the timed maniulation, s, m, h, d + if duration == "s": + seconds = seconds * 1 + elif duration == "m": + seconds = seconds * 60 + elif duration == "h": + seconds = seconds * 60 * 60 + elif duration == "d": + seconds = seconds * 86400 + else: + await ctx.send("Invalid duration input") + return + + except Exception as e: + print(e) + await ctx.send("Invalid time input") return - if not member: - await ctx.send("You must mention a member to mute!") - elif not time: - await ctx.send("You must mention a time!") - else: - if not reason: - reason= "No Reason Mentioned" - guild = ctx.guild - Muted = discord.utils.get(guild.roles, name="Muted") - if not Muted: - Muted = await guild.create_role(name="Muted") - for channel in guild.channels: - await channel.set_permissions(Muted, speak=False, send_messages=False, read_message_history=True, read_messages=False) - await member.add_roles(Muted, reason=reason) - muted_embed = discord.Embed(title="New Punishment!", description=f"🤐 You were muted by {ctx.author.mention} for **{time}** coz of reason: **{reason}** in server **{guild.name}**", color=0xE91E63) - await ctx.send(f":ok_hand: {member.mention} was successfully muted!") + + guild = ctx.guild + Muted = discord.utils.get(guild.roles, name="Muted") + + if not Muted: + Muted = await guild.create_role(name="Muted") + + for channel in guild.channels: + await channel.set_permissions(Muted, speak=False, send_messages=False, read_message_history=True, read_messages=False) + + await member.add_roles(Muted, reason=reason) + muted_embed = discord.Embed(title="New Punishment!", description=f"🤐 You were muted by {ctx.author.mention} for **{time}** coz of reason: **{reason}** in server **{guild.name}**", color=0xE91E63) + await ctx.send(f":ok_hand: {member.mention} was successfully muted!") + try: await member.send(embed=muted_embed) - await asyncio.sleep(time) - await member.remove_roles(Muted) - unmute_embed = discord.Embed(title="Mute over!", description=f'Your mute of time: {time} is over now!\n Reason was: `{reason}`\n Make sure not to repeat it again!', color=0xE91E63) + except HTTPException: + pass + await asyncio.sleep(seconds) + await member.remove_roles(Muted) + unmute_embed = discord.Embed(title="Mute over!", description=f'Your mute of time: {time} is over now!\n Reason was: `{reason}`\n Make sure not to repeat it again!', color=0xE91E63) + try: await member.send(embed=unmute_embed) - else: - await ctx.send(f"** The user is not present in the guild!**") + except HTTPException: + pass + #unmute CMD @@ -166,7 +182,10 @@ async def unmute(self, ctx, member: discord.Member): await member.remove_roles(role) unmute_msg = f"``` You have been un-muted in {ctx.guild.name} by the Moderator - {ctx.author.name}```" await ctx.send(f"{member.mention} was unmuted.") - await member.send(unmute_msg) + try: + await member.send(unmute_msg) + except HTTPException: + pass else: await ctx.send(f"**Is That Person even muted? <:hmm:815854699084644352>**") @@ -219,7 +238,7 @@ def check(msg): # nuke COMMAND @commands.command() - @commands.has_permissions(administrator=True) + @commands.has_permissions(manage_channels=True) async def nuke(self, ctx): channel = ctx.channel positions = ctx.channel.position diff --git a/cogs/nqn.py b/cogs/nqn.py index 4cabd0d..f5d2207 100644 --- a/cogs/nqn.py +++ b/cogs/nqn.py @@ -1,110 +1,106 @@ from discord.ext import commands from discord import utils import discord -import sys -blacklist_servers = [795231055954313236] +# blacklist_servers = [795231055954313236, 773185292211453974] -class Nqn(commands.Cog, name='Nqn'): +class emoji(commands.Cog): def __init__(self, bot): self.bot = bot - def cog_check(self, ctx): - if ctx.guild.id in blacklist_servers: - return + # def cog_check(self, ctx): + # if ctx.guild.id in blacklist_servers: + # return - async def getemote(self, arg): - emoji = utils.get(self.bot.emojis, name = arg.strip(":")) + async def getemote(self, arg): + emoji = utils.get(self.bot.emojis, name = arg.strip(":")) - if emoji is not None: - if emoji.animated: - add = "a" - else: - add = "" - return f"<{add}:{emoji.name}:{emoji.id}>" + if emoji is not None: + if emoji.animated: + add = "a" else: - return None - - async def getinstr(self, content): - ret = [] - - spc = content.split(" ") - cnt = content.split(":") - - if len(cnt) > 1: - for item in spc: - if item.count(":") > 1: - wr = "" - if item.startswith("<") and item.endswith(">"): - ret.append(item) - else: - cnt = 0 - for i in item: - if cnt == 2: + add = "" + return f"<{add}:{emoji.name}:{emoji.id}>" + else: + return None + + async def getinstr(self, content): + ret = [] + spc = content.split(" ") + cnt = content.split(":") + + if len(cnt) > 1: + for item in spc: + if item.count(":") > 1: + wr = "" + if item.startswith("<") and item.endswith(">"): + ret.append(item) + else: + cnt = 0 + for i in item: + if cnt == 2: + aaa = wr.replace(" ", "") + ret.append(aaa) + wr = "" + cnt = 0 + + if i != ":": + wr += i + else: + if wr == "" or cnt == 1: + wr += " : " + cnt += 1 + else: aaa = wr.replace(" ", "") ret.append(aaa) - wr = "" - cnt = 0 + wr = ":" + cnt = 1 - if i != ":": - wr += i - else: - if wr == "" or cnt == 1: - wr += " : " - cnt += 1 - else: - aaa = wr.replace(" ", "") - ret.append(aaa) - wr = ":" - cnt = 1 - - aaa = wr.replace(" ", "") - ret.append(aaa) - else: - ret.append(item) - else: - return content + aaa = wr.replace(" ", "") + ret.append(aaa) + else: + ret.append(item) + else: + return content - return ret + return ret # i added extra indent by mistake -_- - @commands.Cog.listener() - async def on_message(self, message): - if message.author.bot: - return - - if ":" in message.content: - msg = await self.getinstr(message.content) - ret = "" - em = False - smth = message.content.split(":") - if len(smth) > 1: - for word in msg: - if word.startswith(":") and word.endswith(":") and len(word) > 1: - emoji = await self.getemote(word) - if emoji is not None: - em = True - ret += f" {emoji}" - else: - ret += f" {word}" + @commands.Cog.listener() + async def on_message(self, message): + if message.author.bot: + return + + if ":" in message.content: + msg = await self.getinstr(message.content) + ret = "" + em = False + smth = message.content.split(":") + if len(smth) > 1: + for word in msg: + if word.startswith(":") and word.endswith(":") and len(word) > 1: + emoji = await self.getemote(word) + if emoji is not None: + em = True + ret += f" {emoji}" else: ret += f" {word}" + else: + ret += f" {word}" - else: - ret += msg + else: + ret += msg - if em: - webhooks = await message.channel.webhooks() - webhook = utils.get(webhooks, name = "Imposter NQN") - if webhook is None: - webhook = await message.channel.create_webhook(name = "Imposter NQN") - - await webhook.send(ret, username = message.author.name, avatar_url = message.author.avatar_url) - await message.delete() + if em: + webhooks = await message.channel.webhooks() + webhook = utils.get(webhooks, name = "SPIKE NQN") + if webhook is None: + webhook = await message.channel.create_webhook(name = "SPIKE NQN") + await webhook.send(ret, username = message.author.name, avatar_url = message.author.avatar_url) + await message.delete() -def setup(Bot): - Bot.add_cog(Nqn(Bot)) - print("Nqn cog is loaded!") +def setup(bot): + bot.add_cog(emoji(bot)) \ No newline at end of file diff --git a/cogs/owner.py b/cogs/owner.py index b99a01a..db6c157 100644 --- a/cogs/owner.py +++ b/cogs/owner.py @@ -1,4 +1,6 @@ import discord +from discord import colour +from discord.errors import InvalidArgument, NoMoreItems from discord.ext import commands import platform import sys @@ -9,6 +11,7 @@ import aiohttp import importlib import json +from discord.ext.commands.core import command import utils guild = 773185292211453974 @@ -206,4 +209,4 @@ async def reload_error(self, ctx, error): def setup(bot): bot.add_cog(Owner(bot)) - print("Owner cog is Working!") \ No newline at end of file + print("Owner cog is Working!") diff --git a/cogs/say.py b/cogs/say.py index b2ecb05..3bb3c55 100644 --- a/cogs/say.py +++ b/cogs/say.py @@ -2,6 +2,7 @@ from discord.ext import commands import asyncio import random +import datetime class Say(commands.Cog, name='Say'): @@ -12,7 +13,8 @@ def __init__(self, bot): @commands.has_permissions(manage_messages=True) async def embed(self, ctx, title, *, word): await ctx.channel.purge(limit=1) - em = discord.Embed(title=f'{title}', description=f'{word}', color=random.choice(self.bot.color_list)) + em = discord.Embed(title=f'{title}', description=f'{word}', color=random.choice(self.bot.color_list), timestamp=datetime.datetime.utcnow()) + em.set_footer(text=f"By {ctx.author.name}") await ctx.send(embed=em) @commands.command() diff --git a/cogs/utility.py b/cogs/utility.py index 84c8f9f..cbbf098 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -9,12 +9,14 @@ import collections from discord.member import Member import discord.utils +import asyncio class Utility(commands.Cog, name='Utility'): def __init__(self, bot): self.bot = bot + self.times = dict() # suggestion CMD @@ -216,8 +218,7 @@ async def roleinfo(self, ctx, *, role_or_rolename: discord.Role): except: return await ctx.send(f"Couldn't find the role") time = role_or_rolename.created_at - em = discord.Embed(description=f'', color=random.choice( - self.bot.color_list), timestamp=time) + em = discord.Embed(description=f'', color=random.choice(self.bot.color_list), timestamp=time) em.set_author(name=f'{role_or_rolename}', icon_url=f'{ctx.author.avatar_url}') em.set_thumbnail(url=f'{ctx.guild.icon_url}') em.add_field(name='__Info__', value=f'**ID :** {str(role_or_rolename.id)} \n' @@ -226,8 +227,7 @@ async def roleinfo(self, ctx, *, role_or_rolename: discord.Role): f'**Position :** {str(role_or_rolename.position)}\n' f'**Is mentionable :** {str(role_or_rolename.mentionable)}\n' f'**Members in role :** {str(len(role_or_rolename.members))}\n') - em.add_field(name='__Role Permissions__', - value=f', '.join(allowed), inline=False) + em.add_field(name='__Role Permissions__', value=f','.join(allowed) or 'No Valid Perms Enabled on this role!', inline=False) em.set_footer(text="Role created on") await ctx.send(embed=em) @@ -261,6 +261,67 @@ async def channelstats(self, ctx): embed.timestamp = datetime.datetime.utcnow() await ctx.send(embed=embed) +#timer COMMAND + + @commands.command() + @commands.cooldown(1, 10, commands.BucketType.user) + async def timer(self, ctx, time: str = None): + try: + is_there = self.times[ctx.author.id] + now = time.time() + gap = now - is_there['time'] + del self.times[ctx.author.id] + return await ctx.send(embed=discord.Embed( + description='⌚ | Timer was set for {}'.format(await self.convert(int(gap))), + colour=discord.Colour.red() + )) + except KeyError: + if not time: + self.times[ctx.author.id] = { + 'time': time.time() + } + await ctx.send(embed=discord.Embed( + description='⌚ | The timer has been set...', + colour=discord.Colour.red() + )) + else: + try: + time = int(time) + except ValueError: + ctx.command.reset_cooldown(ctx) + return await ctx.send(embed=discord.Embed( + description=' Time to set must a number (counted with minutes)', + colour=discord.Color.red() + )) + await ctx.send(embed=discord.Embed( + description='⌚ | Will remind you in **{}** minutes.'.format(time), + colour=discord.Colour.green() + )) + await asyncio.sleep(time*60) + return await ctx.send(embed=discord.Embed( + description='⏰ | Times Up!', + colour=discord.Color.red() + ), content=ctx.author.mention) + + +#pings COMMAND + + @commands.command(name='Pings') + @commands.cooldown(1, 10, commands.BucketType.user) + @commands.bot_has_guild_permissions(read_message_history=True, read_messages=True) + async def pings(self, ctx, limit: str = '10', user: discord.Member = None): + user = ctx.author if not user else user + try: + limit = int(limit) + except ValueError: + return await ctx.send('The limit for the searching must be a number.') + if limit > 100: + return await ctx.send('Max limit is 100 messages. This is to keep the command consistent.') + counter = 0 + async for message in ctx.channel.history(limit=limit): + if user.mentioned_in(message): + counter += 1 + await ctx.send('You have been pinged {} times in the last {} messages'.format(counter, limit)) """ #poll CMD @@ -339,4 +400,4 @@ async def npm(self, ctx, message): def setup(bot): bot.add_cog(Utility(bot)) - print("Utility Cog is Loaded!") \ No newline at end of file + print("Utility Cog is Loaded!")