Add files via upload

This commit is contained in:
Elmon11 2020-10-25 15:31:18 +01:00 committed by GitHub
parent 7871f1f9fa
commit a3f93a4168
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 348 additions and 0 deletions

71
commands/Moderation.py Normal file
View file

@ -0,0 +1,71 @@
import discord
from discord.ext import commands
import datetime
class Moderation(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.moderator_role_id = 769659653129896023
@commands.command()
@commands.has_permissions(kick_members=True)
async def kick(self, ctx, user: discord.Member, *, reason="No reason specified"):
"""Kicks a user from the guild."""
await user.kick(reason=f'{reason}** **by: {ctx.author.name}')
await ctx.send(embed=discord.Embed(embed=f'{user.name} has been kicked by: {ctx.author.name} for reason: {reason}', colour=0xbc0a1d))
print(f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Kicked {user.name} from {ctx.guild.name}")
@commands.command()
@commands.has_permissions(ban_members=True)
async def ban(self, ctx, user: discord.Member, *, reason="No reason specified"):
"""Bans a user from the guild."""
await user.ban(reason=f'{reason} || by: {ctx.author.name}', delete_message_days=0)
await ctx.send(embed=discord.Embed(description=f'{user.name} has been banned by: {ctx.author.name} for reason: {reason}',colour=0xbc0a1d))
print(f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Banned {user.name} from {ctx.guild.name}")
@commands.command()
@commands.has_permissions(ban_members=True)
async def unban(self, ctx, user: discord.User, *, reason="No reason specified"):
"""Unbans a user from the guild."""
await ctx.guild.unban(user, reason=f'{reason} || by: {ctx.author.name}')
await ctx.send(embed=discord.Embed(description=f'{user.name} has been unbanned by: {ctx.author.name} for reason: {reason}', colour=0xbc0a1d))
print(f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Banned {user.name} from {ctx.guild.name}")
@commands.command()
@commands.has_permissions(manage_messages=True)
async def prune(self, ctx, msgs):
"""Purge messages from a channel."""
channel = ctx.channel
await channel.purge(limit=(int(msgs) + 1))
await ctx.send(embed=discord.Embed(description=f'{ctx.author.name} deleted {msgs} messages',colour=0xbc0a1d))
print(f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] {ctx.author.name} purged {msgs} messages in {ctx.guild.name}')
@commands.command()
@commands.has_permissions(manage_messages=True)
async def mute(self, ctx, member: discord.Member, *, reason=''):
"""Mutes a member of the server."""
mutedrole = discord.utils.get(ctx.guild.roles, name='Muted')
if mutedrole is None:
return await ctx.send(embed=discord.Embed(description="Role Muted doesn't exist", colour=0xbc0a1d))
await member.add_roles(mutedrole, reason = f'{reason} || by {ctx.author.name}')
if reason == '':
reason = 'No reason specified'
await ctx.send(embed=discord.Embed(description=f'{member} muted by: {ctx.author.name} for: {reason}', colour=0xbc0a1d))
print(f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Moderation] Muted {member} in {ctx.guild.name}')
@commands.command()
@commands.has_permissions(manage_messages=True)
async def unmute(self, ctx, member: discord.Member, *, reason="No reason specified"):
"""Unmutes a member of the server."""
mutedrole = discord.utils.get(ctx.guild.roles, name='Muted')
if mutedrole is None:
mutedrole = discord.utils.get(ctx.guild.roles, name='muted')
if mutedrole is None:
return await ctx.send(embed=discord.Embed(description="Role Muted doesn't exist", colour=0xbc0a1d))
await member.remove_roles(mutedrole, reason = f'{reason} || by {ctx.author.name}')
await ctx.send(embed=discord.Embed(description=f'{member} unmuted by {ctx.author.name}', colour=0xbc0a1d))
print(f'[Moderation] Unmuted {member} in {ctx.guild.name}')
def setup(bot):
bot.add_cog(Moderation(bot))

View file

@ -0,0 +1,97 @@
import discord
from discord.ext import commands
import datetime
server_liaison = 769659653096472634
event_host = 769659653096472629
senior_admin = 769659653129896016
admin = 769659653121900553
master_builder = 769659653121900550
def is_staff(ctx):
user = ctx.message.author
for role in user.roles:
if role.id in [admin, senior_admin]:
return True
return False
def is_liaison(ctx):
user = ctx.message.author
for role in user.roles:
if role.id == server_liaison:
return True
return False
def is_senior(ctx):
user = ctx.message.author
for role in user.roles:
if role.id == senior_admin:
return True
return False
class ServerCommands(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
@commands.check(is_liaison)
async def eventhost(self, ctx, user: discord.Member):
'Add or remove event host role from users - liaison only'
eventhostrole = ctx.guild.get_role(event_host)
if eventhostrole in user.roles:
await user.remove_roles(eventhostrole)
await ctx.send(f'```Succesfully took Event Host from {user.name}```')
else:
await user.add_roles(eventhostrole)
await ctx.send(f'```Succesfully added Event Host to {user.name}```')
@commands.command()
@commands.check(is_staff)
async def start(self, ctx):
'Not currently working'
startEmbed = discord.Embed(description='start working out fatass')
await ctx.send(embed=startEmbed)
@commands.command()
@commands.check(is_staff)
async def stop(self, ctx):
'Not currently working'
stopEmbed = discord.Embed(description='stop being so sus')
await ctx.send(embed=stopEmbed)
@commands.command()
@commands.check(is_senior)
async def kill(self, ctx):
'Not currently working'
killEmbed = discord.Embed(description='kill youself')
await ctx.send(embed=killEmbed)
@commands.command()
@commands.check(is_staff)
async def restart(self, ctx):
'Not currently working'
restartEmbed = discord.Embed(description='cant restart a dead server idiot')
await ctx.send(embed=restartEmbed)
@commands.command()
@commands.check(is_senior)
async def console(self, ctx,*, command):
'Not currently working'
await ctx.send(f'```:[{str(datetime.datetime.utcnow().replace(microsecond=0))[11:]} INFO]: {ctx.author.name} issued server command: /{command}```')
@commands.command(aliases=['status'])
async def state(self, ctx):
'Not currently working'
await ctx.send('```The server is currently fucked.```')
@commands.command()
async def list(self, ctx):
'Not currently working'
onlinePlayers = discord.Embed(title='Players Online', description='fuckall mate')
await ctx.send(embed=onlinePlayers)
def setup(bot):
bot.add_cog(ServerCommands(bot))

172
main.py Normal file
View file

@ -0,0 +1,172 @@
import ast
import discord
import datetime
import os
import time
import random
import aiofiles
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
botToken = os.getenv('botToken')
bot = commands.Bot(command_prefix=os.getenv('prefix'), description='TotalFreedom bot help command')
devs = [114348811995840515, 147765181903011840]
def is_dev(ctx):
return ctx.message.author.id in devs
extensions = [
"commands.Moderation",
"commands.ServerCommands"
]
if __name__ == '__main__':
for extension in extensions:
try:
bot.load_extension(extension)
print(f"[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Extensions] {extension} loaded successfully")
except Exception as e:
print("[{} INFO]: [Extensions] {} didn't load {}".format(datetime.datetime.utcnow().replace(microsecond=0), extension, e))
@bot.event
async def on_ready():
bot.reaction_roles = []
for file in ['reactionroles.txt']:
async with aiofiles.open(file, mode='a') as temp:
pass
async with aiofiles.open('reactionroles.txt', mode='r') as file:
lines = await file.readlines()
for line in lines:
data = line.split(' ')
bot.reaction_roles.append((int(data[0]), int(data[1]), data[2].strip('\n')))
print(f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Client] {bot.user.name} is online.')
game = discord.Game('play.totalfreedom.me')
await bot.change_presence(status=discord.Status.online, activity=game)
guildCount = len(bot.guilds)
print(f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Guilds] Bot currently in {guildCount} guilds.')
for guild in bot.guilds:
print(f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Guilds] Connected to guild: {guild.name}, Owner: {guild.owner}')
global starttime
starttime = datetime.datetime.utcnow()
@bot.event
async def on_command_error(ctx, error):
await ctx.send('''```py
{}```'''.format(error))
print(f'[{datetime.datetime.utcnow().replace(microsecond=0)} INFO]: [Commands] {ctx.author} failed running: {ctx.message.content} in guild: {ctx.guild.name}')
@bot.event
async def on_raw_reaction_add(payload):
if payload.member == bot.user:
pass
else:
for role_id, msg_id, emoji in bot.reaction_roles:
if msg_id == payload.message_id and emoji == str(payload.emoji.name.encode('utf-8')):
await payload.member.add_roles(bot.get_guild(payload.guild_id).get_role(role_id))
@bot.event
async def on_raw_reaction_remove(payload):
if payload.member == bot.user:
pass
else:
for role_id, msg_id, emoji in bot.reaction_roles:
if msg_id == payload.message_id and emoji == str(payload.emoji.name.encode('utf-8')):
await bot.get_guild(payload.guild_id).get_member(payload.user_id).remove_roles(bot.get_guild(payload.guild_id).get_role(role_id))
@bot.command()
@commands.has_permissions(manage_roles=True)
async def setreaction(ctx, role : discord.Role=None, msg : discord.Message=None, emoji=None):
if role and msg and emoji :
await msg.add_reaction(emoji)
bot.reaction_roles.append((role.id,msg.id,str(emoji.encode('utf-8'))))
async with aiofiles.open("reactionroles.txt", mode='a') as file:
emoji_utf = emoji.encode('utf-8')
await file.write(f'{role.id} {msg.id} {emoji_utf}\n')
def insert_returns(body):
# insert return stmt if the last expression is a expression statement
if isinstance(body[-1], ast.Expr):
body[-1] = ast.Return(body[-1].value)
ast.fix_missing_locations(body[-1])
# for if statements, we insert returns into the body and the orelse
if isinstance(body[-1], ast.If):
insert_returns(body[-1].body)
insert_returns(body[-1].orelse)
# for with blocks, again we insert returns into the body
if isinstance(body[-1], ast.With):
insert_returns(body[-1].body)
@bot.command(pass_context=True)
@commands.check(is_dev)
async def killbot(ctx):
await ctx.send(f'Bot offline.')
await bot.logout()
@bot.command(name='debug')
@commands.check(is_dev)
async def debug(ctx, *, cmd):
#Evaluates input.
#Input is interpreted as newline seperated statements.
#If the last statement is an expression, that is the return value.
#Usable globals:
# - `bot`: the bot instance
# - `discord`: the discord module
# - `commands`: the discord.ext.commands module
# - `ctx`: the invokation context
# - `__import__`: the builtin `__import__` function
#Such that `>eval 1 + 1` gives `2` as the result.
#The following invokation will cause the bot to send the text '9'
#to the channel of invokation and return '3' as the result of evaluating
#>eval ```
#a = 1 + 2
#b = a * 2
#await ctx.send(a + b)
#a
#```
fn_name = "_eval_expr"
cmd = cmd.strip("` ")
# add a layer of indentation
cmd = "\n".join(f" {i}" for i in cmd.splitlines())
# wrap in async def body
body = f"async def {fn_name}():\n{cmd}"
parsed = ast.parse(body)
body = parsed.body[0].body
insert_returns(body)
env = {
'bot': ctx.bot,
'discord': discord,
'commands': commands,
'ctx': ctx,
'__import__': __import__
}
exec(compile(parsed, filename="<ast>", mode="exec"), env)
result = (await eval(f"{fn_name}()", env))
if result is not None:
await ctx.send(f'''```py
{result}```''')
bot.run(botToken)

8
reactionroles.txt Normal file
View file

@ -0,0 +1,8 @@
769659653121900545 769846027951407105 b'\xf0\x9f\xa7\xa9'
769659653121900545 769859869981016124 b'\xf0\x9f\xa7\xa9'
769659653121900545 769860160528842756 b'\xf0\x9f\xa7\xa9'
769659653121900547 769860160528842756 b'\xf0\x9f\x93\xa2'
769659653121900547 769860347469234188 b'\xf0\x9f\x93\xa2'
769659653121900545 769860160528842756 b'\xf0\x9f\xa7\xa9'
769659653121900545 769860347469234188 b'\xf0\x9f\xa7\xa9'
769659653096472632 769860347469234188 b'\xf0\x9f\x8f\x98\xef\xb8\x8f'