This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from treefroog/cogs
Cogs
- Loading branch information
Showing
16 changed files
with
650 additions
and
308 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,4 @@ | ||
node_modules/* | ||
credentials.json | ||
*.pyc | ||
*.log |
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,78 @@ | ||
from discord.ext import commands | ||
from .utils import checks | ||
import discord | ||
import inspect | ||
import asyncio | ||
|
||
class Admin: | ||
"""Admin-only commands that make the bot dynamic.""" | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@commands.command(hidden=True) | ||
@checks.is_owner() | ||
async def load(self, *, module : str): | ||
"""Loads a module.""" | ||
try: | ||
self.bot.load_extension(module) | ||
except Exception as e: | ||
await self.bot.say('\N{PISTOL}') | ||
await self.bot.say('{}: {}'.format(type(e).__name__, e)) | ||
else: | ||
await self.bot.say('\N{OK HAND SIGN}') | ||
|
||
@commands.command(hidden=True) | ||
@checks.is_owner() | ||
async def unload(self, *, module : str): | ||
"""Unloads a module.""" | ||
try: | ||
self.bot.unload_extension(module) | ||
except Exception as e: | ||
await self.bot.say('\N{PISTOL}') | ||
await self.bot.say('{}: {}'.format(type(e).__name__, e)) | ||
else: | ||
await self.bot.say('\N{OK HAND SIGN}') | ||
|
||
@commands.command(name='reload', hidden=True) | ||
@checks.is_owner() | ||
async def _reload(self, *, module : str): | ||
"""Reloads a module.""" | ||
try: | ||
self.bot.unload_extension(module) | ||
self.bot.load_extension(module) | ||
except Exception as e: | ||
await self.bot.say('\N{PISTOL}') | ||
await self.bot.say('{}: {}'.format(type(e).__name__, e)) | ||
else: | ||
await self.bot.say('\N{OK HAND SIGN}') | ||
|
||
@commands.command(pass_context=True, hidden=True) | ||
@checks.is_owner() | ||
async def debug(self, ctx, *, code : str): | ||
"""Evaluates code.""" | ||
code = code.strip('` ') | ||
python = '```py\n{}\n```' | ||
result = None | ||
|
||
env = { | ||
'bot': self.bot, | ||
'ctx': ctx, | ||
'message': ctx.message, | ||
'server': ctx.message.server, | ||
'channel': ctx.message.channel, | ||
'author': ctx.message.author | ||
} | ||
|
||
try: | ||
result = eval(code, env) | ||
if inspect.isawaitable(result): | ||
result = await result | ||
except Exception as e: | ||
await self.bot.say(python.format(type(e).__name__ + ': ' + str(e))) | ||
return | ||
|
||
await self.bot.say(python.format(result)) | ||
|
||
def setup(bot): | ||
bot.add_cog(Admin(bot)) |
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,48 @@ | ||
from discord.ext import commands | ||
from .utils import checks, formats | ||
import discord | ||
from collections import OrderedDict, deque, Counter | ||
import os, datetime | ||
import re, asyncio | ||
import copy | ||
|
||
|
||
|
||
class Meta: | ||
"""Commands for utilities related to Discord or the Bot itself.""" | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@commands.command(hidden=True) | ||
async def hello(self): | ||
"""Displays my hello message.""" | ||
await self.bot.say('Hello! I\'m a bot made by <@149281074437029890>') | ||
|
||
@commands.command(hidden=True) | ||
async def source(self): | ||
"""displays link to github""" | ||
await self.bot.say('Github: https://github.com/treefroog/tapir-bot') | ||
|
||
@commands.command(rest_is_raw=True, hidden=True, aliases=['say']) | ||
@checks.is_owner() | ||
async def echo(self, *, content): | ||
"""says stuff that I tell it to""" | ||
await self.bot.say(content) | ||
|
||
@commands.command(name='quit', hidden=True, aliases=['close']) | ||
@checks.is_owner() | ||
async def _quit(self): | ||
"""quits tapir-bot""" | ||
await self.bot.logout() | ||
|
||
@commands.command(hidden=True) | ||
@checks.is_owner() | ||
async def commandstats(self): | ||
"""gives me command stats""" | ||
msg = 'Since startup, {} commands have been used.\n{}' | ||
counter = self.bot.commands_used | ||
await self.bot.say(msg.format(sum(counter.values()), counter)) | ||
|
||
def setup(bot): | ||
bot.add_cog(Meta(bot)) |
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,148 @@ | ||
from discord.ext import commands | ||
from .utils import config, checks | ||
from collections import Counter | ||
import re | ||
import discord | ||
import asyncio | ||
|
||
class Mod: | ||
"""Moderation related commands.""" | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
self.config = config.Config('mod.json', loop=bot.loop) | ||
|
||
def bot_user(self, message): | ||
return message.server.me if message.channel.is_private else self.bot.user | ||
|
||
@commands.group(pass_context=True, no_pm=True, hidden=True) | ||
@checks.admin_or_permissions(manage_channels=True) | ||
async def ignore(self, ctx): | ||
"""Handles the bot's ignore lists. | ||
To use these commands, you must have the Bot Admin role or have | ||
Manage Channels permissions. These commands are not allowed to be used | ||
in a private message context. | ||
Users with Manage Roles or Bot Admin role can still invoke the bot | ||
in ignored channels. | ||
""" | ||
if ctx.invoked_subcommand is None: | ||
await self.bot.say('Invalid subcommand passed: {0.subcommand_passed}'.format(ctx)) | ||
|
||
@ignore.command(name='list', pass_context=True) | ||
async def ignore_list(self, ctx): | ||
"""Tells you what channels are currently ignored in this server.""" | ||
|
||
ignored = self.config.get('ignored', []) | ||
channel_ids = set(c.id for c in ctx.message.server.channels) | ||
result = [] | ||
for channel in ignored: | ||
if channel in channel_ids: | ||
result.append('<#{}>'.format(channel)) | ||
|
||
if result: | ||
await self.bot.say('The following channels are ignored:\n\n{}'.format(', '.join(result))) | ||
else: | ||
await self.bot.say('I am not ignoring any channels here.') | ||
|
||
@ignore.command(name='channel', pass_context=True) | ||
async def channel_cmd(self, ctx, *, channel : discord.Channel = None): | ||
"""Ignores a specific channel from being processed. | ||
If no channel is specified, the current channel is ignored. | ||
If a channel is ignored then the bot does not process commands in that | ||
channel until it is unignored. | ||
""" | ||
|
||
if channel is None: | ||
channel = ctx.message.channel | ||
|
||
ignored = self.config.get('ignored', []) | ||
if channel.id in ignored: | ||
await self.bot.say('That channel is already ignored.') | ||
return | ||
|
||
ignored.append(channel.id) | ||
await self.config.put('ignored', ignored) | ||
await self.bot.say('\U0001f44c') | ||
|
||
@ignore.command(name='all', pass_context=True) | ||
@checks.admin_or_permissions(manage_server=True) | ||
async def _all(self, ctx): | ||
"""Ignores every channel in the server from being processed. | ||
This works by adding every channel that the server currently has into | ||
the ignore list. If more channels are added then they will have to be | ||
ignored by using the ignore command. | ||
To use this command you must have Manage Server permissions along with | ||
Manage Channels permissions. You could also have the Bot Admin role. | ||
""" | ||
|
||
ignored = self.config.get('ignored', []) | ||
channels = ctx.message.server.channels | ||
ignored.extend(c.id for c in channels if c.type == discord.ChannelType.text) | ||
await self.config.put('ignored', list(set(ignored))) # make unique | ||
await self.bot.say('\U0001f44c') | ||
|
||
@commands.command(pass_context=True, no_pm=True) | ||
@checks.admin_or_permissions(manage_channels=True) | ||
async def unignore(self, ctx, *, channel : discord.Channel = None): | ||
"""Unignores a specific channel from being processed. | ||
If no channel is specified, it unignores the current channel. | ||
To use this command you must have the Manage Channels permission or have the | ||
Bot Admin role. | ||
""" | ||
|
||
if channel is None: | ||
channel = ctx.message.channel | ||
|
||
# a set is the proper data type for the ignore list | ||
# however, JSON only supports arrays and objects not sets. | ||
ignored = self.config.get('ignored', []) | ||
try: | ||
ignored.remove(channel.id) | ||
except ValueError: | ||
await self.bot.say('Channel was not ignored in the first place.') | ||
else: | ||
await self.bot.say('\U0001f44c') | ||
|
||
@commands.command(no_pm=True) | ||
@checks.admin_or_permissions(manage_server=True) | ||
async def plonk(self, *, member : discord.Member): | ||
"""Bans a user from using the bot. | ||
Note that this ban is **global**. So they are banned from | ||
all servers that they access the bot with. So use this with | ||
caution. | ||
There is no way to bypass a plonk regardless of role or permissions. | ||
The only person who cannot be plonked is the bot creator. So this | ||
must be used with caution. | ||
To use this command you must have the Manage Server permission | ||
or have a Bot Admin role. | ||
""" | ||
|
||
plonks = self.config.get('plonks', []) | ||
if member.id in plonks: | ||
await self.bot.say('That user is already bot banned.') | ||
return | ||
|
||
plonks.append(member.id) | ||
await self.config.put('plonks', plonks) | ||
await self.bot.say('{0.name} has been banned from using the bot.'.format(member)) | ||
|
||
@commands.command(no_pm=True) | ||
@checks.admin_or_permissions(manage_server=True) | ||
async def unplonk(self, *, member : discord.Member): | ||
"""Unbans a user from using the bot. | ||
To use this command you must have the Manage Server permission | ||
or have a Bot Admin role. | ||
""" | ||
|
||
plonks = self.config.get('plonks', []) | ||
|
||
try: | ||
plonks.remove(member.id) | ||
except ValueError: | ||
pass | ||
else: | ||
await self.config.put('plonks', plonks) | ||
await self.bot.say('{0.name} has been unbanned from using the bot.'.format(member)) | ||
|
||
def setup(bot): | ||
bot.add_cog(Mod(bot)) |
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,23 @@ | ||
from discord.ext import commands | ||
from .utils import checks | ||
import discord | ||
import asyncio | ||
|
||
class Ships: | ||
"""all of the Star Citizen ship commands""" | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@commands.group(pass_context=True) | ||
async def ship(self, ctx): | ||
"""Posts a link to an album of the specified ship (no where near done)""" | ||
if ctx.invoked_subcommand is None: | ||
await self.bot.say('Invalid ship: {0.subcommand_passed}'.format(ctx)) | ||
|
||
@ship.command(pass_context=True) | ||
async def carrack(self): | ||
await self.bot.say('Carrack pls http://i.imgur.com/BA3F1OI.png') | ||
|
||
def setup(bot): | ||
bot.add_cog(Ships(bot)) |
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,25 @@ | ||
from discord.ext import commands | ||
from .utils import checks | ||
import discord | ||
import asyncio | ||
|
||
class Star_Citizen: | ||
"""All of the Star Citizen related commands""" | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@commands.command() | ||
async def ben(self): | ||
await self.bot.say('http://i.imgur.com/OLKOQ6H.gif') | ||
|
||
@commands.command() | ||
async def scam(self): | ||
await self.bot.say('Star Citizen is a scam, confirmed by Chris Roberts himself: http://i.imgur.com/UK3D1c0.gifv') | ||
|
||
@commands.command(name='2.4') | ||
async def two_four(self): | ||
await self.bot.say('It\'s not just a meme! http://i.imgur.com/umBUjqW.gif') | ||
|
||
def setup(bot): | ||
bot.add_cog(Star_Citizen(bot)) |
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,31 @@ | ||
from discord.ext import commands | ||
from .utils import config, checks | ||
import random | ||
import discord | ||
import asyncio | ||
|
||
class Tapir: | ||
"""the tapir command(s)""" | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@commands.command() | ||
async def tapir(self): | ||
"""The wonderful tapir command that outputs a random tapir""" | ||
tapir_file = config.Config('tapirs.json') | ||
tapirs = tapir_file.get('tapirs') | ||
tapir = tapirs[random.randrange(len(tapirs))] | ||
await self.bot.say(tapir) | ||
|
||
@commands.command(hidden=True) | ||
@checks.is_owner() | ||
async def save_tapir(self, *, tapir): | ||
"""allows the saving of a tapirs""" | ||
tapir_file = config.Config('tapirs.json', loop=bot.loop) | ||
tapirs = tapir_file.get('tapirs') | ||
tapirs.append(tapir) | ||
tapir_file.put(tapirs) | ||
|
||
def setup(bot): | ||
bot.add_cog(Tapir(bot)) |
Empty file.
Oops, something went wrong.