-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f3d2f7
commit ffb71cc
Showing
2 changed files
with
55 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,66 @@ | ||
# Import Stack | ||
import discord | ||
from discord.ext import commands | ||
import jthon | ||
from pathlib import Path | ||
import os | ||
from cogs.util.errors import NotContributor | ||
|
||
# Variable Defs | ||
config = jthon.load('config') | ||
TOKEN = str(config.get("token")) #pulls the bot token from the hidden config file | ||
bot = commands.Bot(command_prefix="^") | ||
|
||
# Function Defs | ||
def get_prefix(bot, message): #determines the prefix from the config file, if there isn't one, it defaults to "$" | ||
prefix = config.get('prefix') | ||
if not prefix: | ||
prefix = '^' | ||
return commands.when_mentioned_or(*prefix)(bot, message) | ||
# This is the wiretapping module, commands are built to track messages of one particular user. | ||
|
||
def load_some_cogs(): #loads all available extensions, can also be done manually when the admin cog is loaded | ||
bot.startup_extensions = [] | ||
path = Path('./cogs') | ||
for dirpath, dirnames, filenames in os.walk(path): | ||
if dirpath.strip('./') == str(path): | ||
for cog in filenames: | ||
if cog.endswith('.py') and not cog.startswith('_'): | ||
extension = 'cogs.'+cog[:-3] | ||
bot.startup_extensions.append(extension) | ||
#Import Stack | ||
from discord.channel import CategoryChannel | ||
from discord.ext import commands | ||
from discord.ext.commands import has_permissions | ||
import discord | ||
from discord.utils import get | ||
import discord.abc | ||
|
||
if __name__ == "__main__": | ||
for extension in bot.startup_extensions: | ||
try: | ||
bot.load_extension(extension) | ||
print(f'Loaded {extension}') | ||
except Exception as e: | ||
exc = f'{type(e).__name__}: {e}' | ||
print(f'Failed to load extension {extension}\n{exc}') | ||
#Variables | ||
wiretapList = [] | ||
|
||
# Bot Events | ||
@bot.event | ||
async def on_connect(): | ||
print("Connecting...") | ||
#Module Code | ||
class wiretap(commands.Cog): | ||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@bot.event | ||
async def on_ready(): | ||
print(f"We have logged in as {bot.user.name}") | ||
@commands.command(name="startwiretap", aliases=["wiretap", "swt"], hidden=True) | ||
@has_permissions(administrator=True) | ||
async def startWiretap(self, ctx, pinguser: discord.User): | ||
global wiretapList | ||
guild = ctx.message.guild | ||
category = get(guild.categories, name="FISA Court") | ||
categoryid = get(guild.categories, name="FISA Court").id | ||
overwrites = {guild.default_role: discord.PermissionOverwrite(read_messages=False)} | ||
userid = pinguser.id | ||
|
||
@bot.event #Handles the two most common errors and a catch-all | ||
async def on_command_error(ctx, error): | ||
if isinstance(error, commands.CommandOnCooldown): | ||
embed = discord.Embed(title=f'Command: {ctx.command.name}', colour=discord.Colour(0xFF0000), description=f"{ctx.author.name}, you are on cooldown for this command for {error.retry_after:.2f}s") | ||
await ctx.send(embed=embed) | ||
return | ||
if category is None: | ||
category = await guild.create_category_channel("FISA Court") | ||
categoryid = get(guild.categories, name="FISA Court").id | ||
|
||
if isinstance(error, NotContributor): | ||
e = discord.Embed(colour=discord.Colour(0xFF0000), description=f"{ctx.author.name}, you aren't a contributor.") | ||
await ctx.send(embed=e) | ||
return | ||
|
||
else: | ||
e = discord.Embed(colour=discord.Colour(0xFF0000), description=f"{error}") | ||
await ctx.send(embed=e) | ||
if userid in wiretapList: | ||
await ctx.send("This user is already wiretapped.") | ||
else: | ||
wiretapList.append(userid) | ||
await ctx.send("FISA Warrant Approved, Wiretap Opened.") | ||
if get(guild.channels, name=str(userid)) is None: | ||
await guild.create_text_channel(name=userid, category=category, overwrites=overwrites) | ||
|
||
@bot.event # Handles DMs while bot is online | ||
async def on_message(message): | ||
if isinstance(message.channel, discord.DMChannel): | ||
if str(message.author) != "MSCHF Man#1788": | ||
print(f'Private message from {message.author}: "{message.content}"') | ||
l = open("DMLog.txt", "a") | ||
l.write(f'\nPrivate message from {message.author}: "{message.content}"') | ||
l.close() | ||
await bot.process_commands(message) | ||
|
||
# Bot Commands | ||
@commands.is_owner() #command to change the prefix, must be owner of the bot, writes to config file so to be persistent | ||
@bot.command(aliases=['sp']) | ||
async def setprefix(ctx, prefix: str=None): | ||
if not prefix or len(prefix) >= 3: | ||
await ctx.send("Please provide the prefix you would like to use between 1-2 chars.") | ||
else: | ||
config['prefix'] = prefix | ||
config.save() | ||
await ctx.send(f'Prefix updated to: {prefix}') | ||
@commands.command(name="closewiretap", aliases=["endwiretap","cwt","ewt"], hidden=True) | ||
@has_permissions(administrator=True) | ||
async def endWiretap(self, ctx, pinguser: discord.User): | ||
global wiretapList | ||
if pinguser.id in wiretapList: | ||
wiretapList.remove(pinguser.id) | ||
else: | ||
await ctx.send("That user is not wiretapped.") | ||
|
||
@commands.is_owner() | ||
@commands.command() | ||
async def shutdown(self, ctx): #fairly self explanatory, allows the owner to shutdown the bot from discord | ||
await ctx.send("Command Received; Bot Shutdown Imminent.") | ||
print("Shutdown Command issued from within Discord...") | ||
exit() | ||
@commands.Cog.listener() | ||
async def on_message(self, given_message): | ||
guild = given_message.guild | ||
if given_message.author.id in wiretapList: | ||
#print("Message from wiretap flagged user.") | ||
if not isinstance(given_message.channel, discord.DMChannel): | ||
#print("AND not a DM.") | ||
if get(guild.channels, name=str(given_message.author.id)) is not None: | ||
#print("AND user has an existing wiretap channel.") | ||
sendchannel = get(guild.channels, name=str(given_message.author.id)) | ||
await sendchannel.send(str(given_message.author.name)+" sent: "+'`'+str(given_message.content)+'`'+" in "+str(given_message.channel.name)) | ||
|
||
# Run Code | ||
bot = commands.Bot(command_prefix=get_prefix) | ||
load_some_cogs() | ||
bot.run(TOKEN, bot=True, reconnect=True) | ||
def setup(bot): | ||
bot.add_cog(wiretap(bot)) |