Deleted the old repo because I leaked the token
And I can't use git very well after midnight anyway
This commit is contained in:
commit
d207d39fb0
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
||||
## AutoArch
|
||||
A simple bot written in discord.py, with a few moderation/utility/random commands.
|
||||
|
||||
## How to run
|
||||
Download/clone this, and install discord.py 1.0.0 or greater. Then put your token in `settings.py` and run it with Python 3.5.3 or greater :)
|
67
checks.py
Normal file
67
checks.py
Normal file
@ -0,0 +1,67 @@
|
||||
import discord
|
||||
|
||||
# Custom checks
|
||||
|
||||
# Returns true if the user has either the ban_members permission *or* administrator permission.
|
||||
def admin_or_ban(ctx):
|
||||
permissions = ctx.author.guild_permissions
|
||||
if permissions.administrator == True or permissions.ban_members == True:
|
||||
return True
|
||||
else:
|
||||
raise(discord.ext.commands.MissingPermissions(missing_perms=['ban_members']))
|
||||
|
||||
# Returns true if the user has either the kick_members permission *or* administrator permission.
|
||||
def admin_or_kick(ctx):
|
||||
permissions = ctx.author.guild_permissions
|
||||
if permissions.administrator == True or permissions.kick_members == True:
|
||||
return True
|
||||
else:
|
||||
raise(discord.ext.commands.MissingPermissions(missing_perms=['kick_members']))
|
||||
|
||||
# Returns true if the user has either the manage_guild permission *or* administrator permission.
|
||||
def admin_or_manage_guild(ctx):
|
||||
permissions = ctx.author.guild_permissions
|
||||
if permissions.administrator == True or permissions.manage_guild == True:
|
||||
return True
|
||||
else:
|
||||
raise(discord.ext.commands.MissingPermissions(missing_perms=['manage_guild']))
|
||||
|
||||
# Returns true if the user has either the manage_messages permission *or* administrator permission.
|
||||
def admin_or_manage_messages(ctx):
|
||||
permissions = ctx.author.guild_permissions
|
||||
if permissions.administrator == True or permissions.manage_messages == True:
|
||||
return True
|
||||
else:
|
||||
raise(discord.ext.commands.MissingPermissions(missing_perms=['manage_messages']))
|
||||
|
||||
# Returns true if the bot has either the ban_members permission *or* administrator permission.
|
||||
def bot_admin_or_ban(ctx):
|
||||
permissions = ctx.guild.me.guild_permissions
|
||||
if permissions.administrator == True or permissions.ban_members == True:
|
||||
return True
|
||||
else:
|
||||
raise(discord.ext.commands.BotMissingPermissions(missing_perms=['ban_members']))
|
||||
|
||||
# Returns true if the bot has either the kick_members permission *or* administrator permission.
|
||||
def bot_admin_or_kick(ctx):
|
||||
permissions = ctx.guild.me.guild_permissions
|
||||
if permissions.administrator == True or permissions.kick_members == True:
|
||||
return True
|
||||
else:
|
||||
raise(discord.ext.commands.BotMissingPermissions(missing_perms=['kick_members']))
|
||||
|
||||
# Returns true if the bot has either the manage_guild permission *or* administrator permission.
|
||||
def bot_admin_or_manage_guild(ctx):
|
||||
permissions = ctx.guild.me.guild_permissions
|
||||
if permissions.administrator == True or permissions.manage_guild == True:
|
||||
return True
|
||||
else:
|
||||
raise(discord.ext.commands.BotMissingPermissions(missing_perms=['manage_guild']))
|
||||
|
||||
# Returns true if the user has either the manage_messages permission *or* administrator permission.
|
||||
def bot_admin_or_manage_messages(ctx):
|
||||
permissions = ctx.guild.me.guild_permissions
|
||||
if permissions.administrator == True or permissions.manage_messages == True:
|
||||
return True
|
||||
else:
|
||||
raise(discord.ext.commands.BotMissingPermissions(missing_perms=['manage_messages']))
|
136
cogs.py
Normal file
136
cogs.py
Normal file
@ -0,0 +1,136 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import random
|
||||
import settings
|
||||
import checks
|
||||
|
||||
class Moderation(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.custom_icon = '\U0001f528'
|
||||
|
||||
@commands.command(help = 'Bans any number of mentioned users.')
|
||||
@commands.check(checks.admin_or_ban)
|
||||
@commands.check(checks.bot_admin_or_ban)
|
||||
@commands.guild_only()
|
||||
async def ban(self, ctx, *, args):
|
||||
members = ctx.message.mentions
|
||||
if len(members) == 0:
|
||||
await ctx.send('Please mention at least one member to ban.')
|
||||
return
|
||||
i = 0
|
||||
for user in members:
|
||||
try:
|
||||
await ctx.guild.ban(user)
|
||||
i += 1
|
||||
except:
|
||||
await ctx.send("Error: Could not ban "+str(user))
|
||||
await ctx.send('Banned '+str(i)+' member(s).')
|
||||
|
||||
@commands.command(help = 'Kicks any number of mentioned users.')
|
||||
@commands.check(checks.admin_or_kick)
|
||||
@commands.check(checks.bot_admin_or_kick)
|
||||
@commands.guild_only()
|
||||
async def kick(self, ctx, *, args):
|
||||
members = ctx.message.mentions
|
||||
if len(members) == 0:
|
||||
await ctx.send('Please mention at least one member to kick.')
|
||||
return
|
||||
i = 0
|
||||
for user in members:
|
||||
try:
|
||||
await ctx.guild.kick(user)
|
||||
i += 1
|
||||
except:
|
||||
await ctx.send("Error: Could not kick "+str(user))
|
||||
await ctx.send('Kicked '+str(i)+' member(s).')
|
||||
|
||||
@commands.command(help = 'Mass-deletes a specified number of messages in the current channel.')
|
||||
@commands.check(checks.bot_admin_or_manage_messages)
|
||||
@commands.check(checks.admin_or_manage_messages)
|
||||
async def clear(self, ctx, amount : int):
|
||||
if amount < 1:
|
||||
await ctx.send('You need')
|
||||
await ctx.message.delete()
|
||||
i = 0
|
||||
async for message in ctx.channel.history(limit = amount):
|
||||
try:
|
||||
await message.delete()
|
||||
i += 1
|
||||
except:
|
||||
continue
|
||||
await ctx.send('Cleared '+str(i)+' messages.', delete_after = 5)
|
||||
|
||||
@commands.command(help = 'Adds a vote in the #voting channel, if it exists.')
|
||||
@commands.check(checks.admin_or_manage_guild)
|
||||
@commands.guild_only()
|
||||
async def vote(self, ctx, *, args):
|
||||
vote_embed = discord.Embed(
|
||||
title = 'Vote!',
|
||||
description = args,
|
||||
colour = discord.Colour.gold()
|
||||
)
|
||||
|
||||
for channel in ctx.guild.channels:
|
||||
if channel.name == 'voting':
|
||||
try:
|
||||
msg = await channel.send(embed=vote_embed)
|
||||
await msg.add_reaction('\U0001f44d')
|
||||
await msg.add_reaction('\U0001f44e')
|
||||
await ctx.message.add_reaction('\U00002705')
|
||||
except:
|
||||
await ctx.message.add_reaction('\U0000274e')
|
||||
return
|
||||
|
||||
class Fun(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.custom_icon = '\U0001f6a9'
|
||||
|
||||
@commands.command(name = '8ball', help = 'Returns a random response to a yes/no question.')
|
||||
async def _8ball(self, ctx, *, args=''):
|
||||
choices = ['Maybe...', 'Not entirely sure.', 'Seems probable.', 'Count on it.', 'Most definitely.', 'Would not bet on it.', 'Unsure. Unlikely though.', 'Oh, definitely not.']
|
||||
choice = random.choice(choices)
|
||||
choice_embed = discord.Embed(
|
||||
description = choice,
|
||||
colour = discord.Colour.gold()
|
||||
)
|
||||
choice_embed.set_footer(text=random.choice(settings.quotes_short))
|
||||
choice_embed.set_author(name=str(ctx.author), icon_url=ctx.author.avatar_url)
|
||||
await ctx.send(embed=choice_embed)
|
||||
|
||||
@commands.command(help = '"Let Me Google That For You": Returns a link to search the term on Google.')
|
||||
async def lmgtfy(self, ctx, *, term):
|
||||
msg = 'https://google.com/search?q=' + term.replace(' ', '+')
|
||||
await ctx.send(msg)
|
||||
|
||||
@commands.command(help = 'Randomly picks an option from a comma-separated list.')
|
||||
async def choose(self, ctx, *, options):
|
||||
picks = options.split(',')
|
||||
choice = random.choice(picks).strip()
|
||||
pick_embed = discord.Embed(
|
||||
description = 'I pick '+choice+'.',
|
||||
colour = discord.Colour.gold()
|
||||
)
|
||||
pick_embed.set_footer(text=random.choice(settings.quotes_short))
|
||||
pick_embed.set_author(name=str(ctx.author), icon_url=ctx.author.avatar_url)
|
||||
await ctx.send(embed=pick_embed)
|
||||
|
||||
class Utility(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.custom_icon = '\U00002699'
|
||||
|
||||
@commands.command(help = "Links a mentioned user's avatar.")
|
||||
async def avatar(self, ctx, member : discord.Member):
|
||||
await ctx.send(member.avatar_url)
|
||||
|
||||
@commands.command(help = 'Invite link for the bot.')
|
||||
async def invite(self, ctx):
|
||||
invite_embed = discord.Embed(
|
||||
description = '[Invite me!](https://discordapp.com/api/oauth2/authorize?client_id=576776255513296896&permissions=0&scope=bot)\n'+random.choice(settings.quotes),
|
||||
colour = discord.Colour.gold()
|
||||
)
|
||||
invite_embed.set_thumbnail(url=ctx.bot.user.avatar_url)
|
||||
invite_embed.set_author(name = str(ctx.author), icon_url = ctx.author.avatar_url)
|
||||
await ctx.send(embed=invite_embed)
|
107
main.py
Normal file
107
main.py
Normal file
@ -0,0 +1,107 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import cogs
|
||||
import settings
|
||||
import random
|
||||
|
||||
bot = commands.Bot(command_prefix='=')
|
||||
|
||||
bot.add_cog(cogs.Moderation(bot))
|
||||
bot.add_cog(cogs.Fun(bot))
|
||||
bot.add_cog(cogs.Utility(bot))
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
activity = discord.Activity(name=bot.command_prefix+'help', type=discord.ActivityType.watching)
|
||||
await bot.change_presence(activity = activity)
|
||||
print('Logged in as '+str(bot.user)+'\n---\nGuilds: '+str(len(bot.guilds)))
|
||||
|
||||
@bot.event
|
||||
async def on_command_error(ctx, error):
|
||||
if isinstance(error, discord.ext.commands.MissingPermissions):
|
||||
await ctx.send("You don't have the required permissions to use that command.\nMissing permission(s): `"+', '.join(error.missing_perms)+'`.')
|
||||
if isinstance(error, discord.ext.commands.BotMissingPermissions):
|
||||
await ctx.send("I don't have permission to do that here!\nAsk a server owner to give me the `"+', '.join(error.missing_perms)+"` permission(s).")
|
||||
if isinstance(error, discord.ext.commands.MissingRequiredArgument):
|
||||
await ctx.send("Looks like you're missing a required argument there.")
|
||||
if isinstance(error, discord.ext.commands.BadArgument):
|
||||
await ctx.send("Invalid argument(s) provided.")
|
||||
print(str(error))
|
||||
class AutoArchHelpCommand(commands.MinimalHelpCommand):
|
||||
def get_command_signature(self, command):
|
||||
return '{0.clean_prefix}{1.qualified_name} {1.signature}'.format(self, command)
|
||||
|
||||
async def send_bot_help(self, mapping):
|
||||
ctx = self.context
|
||||
help_embed = discord.Embed(
|
||||
title = 'Commands',
|
||||
description = self.get_opening_note(),
|
||||
colour = discord.Colour.gold()
|
||||
)
|
||||
help_embed.set_footer(text = random.choice(settings.quotes_short))
|
||||
help_embed.set_author(name=str(ctx.author), icon_url=ctx.author.avatar_url)
|
||||
for cog in mapping.keys():
|
||||
|
||||
name = 'Other'
|
||||
if cog != None:
|
||||
name = cog.qualified_name
|
||||
if hasattr(cog, 'custom_icon'):
|
||||
name = cog.custom_icon + ' ' + name
|
||||
|
||||
help_embed.add_field(name = name, value = ', '.join([command.name for command in mapping[cog]]))
|
||||
|
||||
await self.get_destination().send(embed = help_embed)
|
||||
|
||||
async def send_command_help(self, command):
|
||||
ctx = self.context
|
||||
help_embed = discord.Embed(
|
||||
title = self.get_command_signature(command),
|
||||
description = command.help,
|
||||
colour = discord.Colour.gold()
|
||||
)
|
||||
help_embed.set_footer(text = random.choice(settings.quotes_short))
|
||||
help_embed.set_author(name=str(ctx.author), icon_url=ctx.author.avatar_url)
|
||||
|
||||
await self.get_destination().send(embed = help_embed)
|
||||
|
||||
async def send_cog_help(self, cog):
|
||||
ctx = self.context
|
||||
commands = ', '.join([command.qualified_name for command in cog.get_commands()])
|
||||
help_embed = discord.Embed(
|
||||
title = cog.qualified_name,
|
||||
description = commands,
|
||||
colour = discord.Colour.gold()
|
||||
)
|
||||
help_embed.set_footer(text = random.choice(settings.quotes_short))
|
||||
help_embed.set_author(name=str(ctx.author), icon_url=ctx.author.avatar_url)
|
||||
|
||||
await self.get_destination().send(embed = help_embed)
|
||||
|
||||
async def send_group_help(self, group):
|
||||
ctx = self.context
|
||||
commands = ', '.join([command.qualified_name for command in group.commands])
|
||||
help_embed = discord.Embed(
|
||||
title = group.qualified_name + ' Subcommands',
|
||||
description = commands,
|
||||
colour = discord.Colour.gold()
|
||||
)
|
||||
help_embed.set_footer(text = random.choice(settings.quotes_short))
|
||||
help_embed.set_author(name=str(ctx.author), icon_url=ctx.author.avatar_url)
|
||||
|
||||
await self.get_destination().send(embed = help_embed)
|
||||
|
||||
@bot.command(help = 'Link to the bot\'s GitHub repo.')
|
||||
async def source(ctx):
|
||||
source_embed = discord.Embed(
|
||||
title = 'Bot Source',
|
||||
description = 'The full source code is available at\n'+settings.source+'\nand is licensed under '+settings.license+'.',
|
||||
colour = discord.Colour.gold()
|
||||
)
|
||||
source_embed.set_thumbnail(url = ctx.bot.user.avatar_url)
|
||||
source_embed.set_footer(text = random.choice(settings.quotes_short))
|
||||
source_embed.set_author(name=str(ctx.author), icon_url=ctx.author.avatar_url)
|
||||
await ctx.send(embed = source_embed)
|
||||
|
||||
bot.help_command = AutoArchHelpCommand()
|
||||
|
||||
bot.run(settings.token)
|
22
settings.py
Normal file
22
settings.py
Normal file
@ -0,0 +1,22 @@
|
||||
token = 'Get your own'
|
||||
quotes = [
|
||||
'"All we have to decide is what to do with the time that is given us."',
|
||||
'"Fly, you fools!"',
|
||||
'"So it begins, the great battle of our time..."',
|
||||
'"Fool of a Took! Throw youself in next time and spare us"',
|
||||
'Fun fact: The Rhorrhim were given the plains of Rohan by one of the early Stewards of Gondor, when they came to Gondor\'s aid.',
|
||||
'Fun fact: Five wizards set out from the halls of the Valar, and we know the fates of three pretty well. But what happened to the two Blue Wizards during their journeys with Saruman? Tolkien left it a mystery...',
|
||||
'"Yes, but what about second breakfast?" "I don\'t think he\'s heard of second breakfast, Pip."',
|
||||
'"A wizard is never late, nor is he early; he arrives precisely when he means to."\n*Later, in Rivendell*\n"Sorry, Frodo, I was... delayed."'
|
||||
]
|
||||
quotes_short = [
|
||||
'"For Frodo!"',
|
||||
'"I would have followed you, my brother, my captain, my king!"',
|
||||
'"Nine there were that set out from Rivendell, but only eight here stand."',
|
||||
'Far over the misty mountains cold / To dungeons deep and caverns old',
|
||||
'"I can\'t carry it for you, Mr. Frodo, but I can carry you!"',
|
||||
'"Fly, you fools!"',
|
||||
'"Gondor calls for aid!" "And Rohan will answer!"'
|
||||
]
|
||||
source = 'https://github.com/archfan7411/AutoArch'
|
||||
license = 'MIT'
|
Loading…
x
Reference in New Issue
Block a user