diff --git a/bot.py b/bot.py index 4d7f923..97cf68e 100644 --- a/bot.py +++ b/bot.py @@ -1,7 +1,10 @@ +import asyncio import random import os import platform import sys +import traceback + import discord from discord.ext import commands from discord import app_commands @@ -21,30 +24,52 @@ intents = discord.Intents.all() intents.members = True intents.message_content = True - -bot = commands.Bot(command_prefix="?", description=description, intents=intents) - - libs = [ "jishaku", + "lib.mod", ] +def get_prefix(bot, message): -@bot.event -async def on_ready(): + prefixes = ["?"] + return commands.when_mentioned_or(*prefixes)(bot, message) - for lib in libs: - await bot.load_extension(lib) - print(f"\n[^] Loaded {len(libs)} extensions loaded successfully.") -# for guild in bot.guilds: -# await bot.tree.sync(guild=discord.Object(id=guild.id)) -# print(f"[^] Sync'd application commands to {len(bot.guilds)} servers") +class Bot(commands.Bot): - print(f"[*] Logged in as {bot.user} (ID: {bot.user.id})") - game = discord.Game(name="https://traps.moe",activity=random.randint(0,3)) - await bot.change_presence(status=discord.Status.online,activity=game) - print("------") + async def on_ready(self): + for lib in libs: + try: + bot.load_extension(lib) + except Exception as e: + print(f'[!] Failed to load extension: {lib}') + traceback.print_exc() + finally: + print(f"\n[^] Loaded {len(libs)} extensions loaded successfully.") + + # for guild in bot.guilds: + # await bot.tree.sync(guild=discord.Object(id=guild.id)) + # print(f"[^] Sync'd application commands to {len(bot.guilds)} servers") + + print(f"[*] Logged in as {bot.user} (ID: {bot.user.id})") + game = discord.Game(name="https://traps.moe", activity=random.randint(0, 3)) + await bot.change_presence(status=discord.Status.online, activity=game) + print("------") + + +if sys.platform == "Linux": + asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) + loop = asyncio.get_event_loop() +else: + asyncio.set_event_loop_policy(winloop.EventLoopPolicy()) + loop = asyncio.get_event_loop() + +bot = Bot( + command_prefix=get_prefix, + description=description, + intents=intents, + loop=loop, +) @bot.command() @@ -64,9 +89,4 @@ async def first_slash(ctx): await ctx.send("You executed the slash command!") -if sys.platform == "Linux": - uvloop.install() -else: - winloop.install() - bot.run(TOKEN) diff --git a/lib/checks.py b/lib/checks.py new file mode 100644 index 0000000..09a91a9 --- /dev/null +++ b/lib/checks.py @@ -0,0 +1,35 @@ +from discord.ext import commands + +# Copyright (C) Flumboni - All Rights Reserved +# Unauthorized copying of this file, via any medium is strictly prohibited +# Proprietary and confidential +def check_flum(): + async def predicate(ctx): + ids = [320825953154760704, 344273597612818444, 274983796414349313] + return ctx.author.id not in ids + return commands.check(predicate) + +def check_bot(): + async def predicate(ctx): + return not ctx.author.bot + return commands.check(predicate) + +async def check(ctx): + ids = [232948417087668235, 124316478978785283, 131131701148647424] + return ctx.author.id in ids +def _check(): + return commands.check(check) + +def get_user(message, user): + try: + member = message.mentions[0] + except: + member = message.guild.get_member_named(user) + if not member: + try: + member = message.guild.get_member(int(user)) + except ValueError: + pass + if not member: + return None + return member \ No newline at end of file diff --git a/lib/mod.py b/lib/mod.py new file mode 100644 index 0000000..7bb61cf --- /dev/null +++ b/lib/mod.py @@ -0,0 +1,82 @@ +import discord +from discord.ext import commands +from lib.checks import get_user + +class Mod(commands.Cog): + + def __init__(self, bot): + self.bot = bot + + @commands.has_permissions(manage_messages=True) + @commands.command(aliases=['hban'], pass_context=True) + async def hackban(self, ctx, user_id: int): + author = ctx.message.author + guild = author.guild + + user = guild.get_member(user_id) + if user is not None: + return await ctx.invoke(self.ban, user=user) + + try: + await self.bot.http.ban(user_id, guild.id, 0) + await ctx.send(f'Banned user: {user_id}') + except discord.NotFound: + await ctx.send('Could not find user. ') + + except discord.errors.Forbidden: + await ctx.send('Could not ban user. Not enough permissions.') + + @commands.has_permissions(manage_messages=True) + @commands.command(aliases=['p'], pass_context=True, no_pm=True) + async def purge(self, ctx, msgs: int, members="everyone", *, txt=None): + @property + def destination(self): + return self.context.message.author if self.bot.pm_help else self.context.message.channel + + ''' + Purge last n messages or nmessages with a word. Requires Manage Messages permission. [p]help purge for more info. + + Ex: + + [p]purge 20 - deletes the last 20 messages in a channel sent by anyone. + [p]purge 20 everyone stuff - deletes any messages in the last 20 messages that contain the word 'stuff'. + [p]purge 20 @appu1232 - deletes any messages in the last 20 messages that were sent by appu1232. + [p]purge 20 "@appu1232, LyricLy, 435254873976547426" hello - deletes any messages in the last 20 messages that were sent by appu1232, LyricLy or thecommondude that contain the word 'stuff'. + ''' + await ctx.message.delete() + content = f'I deleted {msgs} message(s) 👻' + member_object_list = [] + if members != "everyone": + member_list = [x.strip() for x in members.split(",")] + for member in member_list: + if "@" in member: + member = member[3 if "!" in member else 2:-1] + if member.isdigit(): + member_object = ctx.guild.get_member(int(member)) + else: + member_object = ctx.guild.get_member_named(member) + if not member_object: + return await ctx.send(self.bot.bot_prefix + "Invalid user.") + else: + member_object_list.append(member_object) + + if msgs < 10000: + async for message in ctx.message.channel.history(limit=msgs): + try: + if txt: + if not txt.lower() in message.content.lower(): + continue + if member_object_list: + if not message.author in member_object_list: + continue + + await message.delete() + except discord.Forbidden: + await ctx.send("I do not have permission to delete other users messages.") + else: + await ctx.send('Too many messages to delete. Enter a number < 10000') + + await ctx.send(content=content,delete_after=15.0) + +def setup(bot): + bot.add_cog(Mod(bot)) \ No newline at end of file