2017-03-08 11:35:30 +13:00
|
|
|
from discord.ext import commands
|
2017-03-26 16:39:18 +13:00
|
|
|
import discord
|
2017-03-08 11:35:30 +13:00
|
|
|
|
|
|
|
from . import utils
|
|
|
|
|
2017-03-26 16:39:18 +13:00
|
|
|
import asyncio
|
|
|
|
import rethinkdb as r
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-07-23 23:59:02 +12:00
|
|
|
class Tags:
|
|
|
|
"""This class contains all the commands for custom tags"""
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2017-03-08 11:35:30 +13:00
|
|
|
@commands.command(no_pm=True)
|
|
|
|
@utils.custom_perms(send_messages=True)
|
2016-07-23 23:59:02 +12:00
|
|
|
async def tags(self, ctx):
|
2016-11-29 17:55:55 +13:00
|
|
|
"""Prints all the custom tags that this server currently has
|
|
|
|
|
|
|
|
EXAMPLE: !tags
|
|
|
|
RESULT: All tags setup on this server"""
|
2017-03-26 16:39:18 +13:00
|
|
|
tags = await utils.get_content('tags', str(ctx.message.guild.id))
|
2017-03-26 16:46:36 +13:00
|
|
|
if tags and len(tags['tags']) > 0:
|
2017-03-26 16:39:18 +13:00
|
|
|
entries = [t['trigger'] for t in tags['tags']]
|
|
|
|
pages = utils.Pages(self.bot, message=ctx.message, entries=entries)
|
|
|
|
await pages.paginate()
|
|
|
|
else:
|
|
|
|
await ctx.send("There are no tags setup on this server!")
|
2016-07-23 23:59:02 +12:00
|
|
|
|
2017-03-08 11:35:30 +13:00
|
|
|
@commands.group(invoke_without_command=True, no_pm=True)
|
|
|
|
@utils.custom_perms(send_messages=True)
|
2016-07-23 23:59:02 +12:00
|
|
|
async def tag(self, ctx, *, tag: str):
|
|
|
|
"""This can be used to call custom tags
|
2017-03-26 16:39:18 +13:00
|
|
|
The format to call a custom tag is !tag <tag>
|
|
|
|
|
|
|
|
EXAMPLE: !tag butts
|
|
|
|
RESULT: Whatever you setup for the butts tag!!"""
|
|
|
|
tags = await utils.get_content('tags', str(ctx.message.guild.id))
|
2017-03-26 17:00:07 +13:00
|
|
|
if tags and len(tags['tags']) > 0:
|
2017-03-26 16:39:18 +13:00
|
|
|
for t in tags['tags']:
|
|
|
|
if t['trigger'] == tag:
|
|
|
|
await ctx.send(t['result'])
|
|
|
|
return
|
|
|
|
await ctx.send("There is no tag called {}".format(tag))
|
2017-03-26 17:00:07 +13:00
|
|
|
else:
|
2017-03-26 16:39:18 +13:00
|
|
|
await ctx.send("There are no tags setup on this server!")
|
2016-07-23 23:59:02 +12:00
|
|
|
|
2017-03-26 16:39:18 +13:00
|
|
|
|
|
|
|
@tag.command(name='add', aliases=['create', 'setup'], no_pm=True)
|
|
|
|
@utils.custom_perms(send_messages=True)
|
|
|
|
async def add_tag(self, ctx):
|
2016-07-23 23:59:02 +12:00
|
|
|
"""Use this to add a new tag that can be used in this server
|
2016-11-29 17:55:55 +13:00
|
|
|
|
2017-03-26 16:39:18 +13:00
|
|
|
EXAMPLE: !tag add
|
|
|
|
RESULT: A follow-along in order to create a new tag"""
|
|
|
|
def check(m):
|
|
|
|
return m.channel == ctx.message.channel and m.author == ctx.message.author and len(m.content) > 0
|
|
|
|
my_msg = await ctx.send("Ready to setup a new tag! What do you want the trigger for the tag to be?")
|
|
|
|
|
2016-08-05 03:47:34 +12:00
|
|
|
try:
|
2017-03-26 16:39:18 +13:00
|
|
|
msg = await self.bot.wait_for("message", check=check, timeout=60)
|
|
|
|
except asyncio.TimeoutError:
|
|
|
|
await ctx.send("You took too long!")
|
2016-08-05 03:47:34 +12:00
|
|
|
return
|
2016-08-17 12:45:01 +12:00
|
|
|
|
2017-03-26 16:39:18 +13:00
|
|
|
trigger = msg.content
|
|
|
|
try:
|
|
|
|
await my_msg.delete()
|
|
|
|
await msg.delete()
|
|
|
|
except discord.Forbidden:
|
|
|
|
pass
|
|
|
|
|
|
|
|
my_msg = await ctx.send("Alright, your new tag can be called with {}!\n\nWhat do you want to be displayed with this tag?".format(trigger))
|
|
|
|
|
|
|
|
try:
|
|
|
|
msg = await self.bot.wait_for("message", check=check, timeout=60)
|
|
|
|
except asyncio.TimeoutError:
|
|
|
|
await ctx.send("You took too long!")
|
2016-12-13 04:52:04 +13:00
|
|
|
return
|
2017-03-26 16:39:18 +13:00
|
|
|
|
|
|
|
result = msg.content
|
|
|
|
try:
|
|
|
|
await my_msg.delete()
|
|
|
|
await msg.delete()
|
|
|
|
except discord.Forbidden:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# The different DB settings
|
|
|
|
tag = {
|
|
|
|
'author': str(ctx.message.author.id),
|
|
|
|
'trigger': trigger,
|
|
|
|
'result': result
|
|
|
|
}
|
|
|
|
entry = {
|
|
|
|
'server_id': str(ctx.message.guild.id),
|
|
|
|
'tags': [tag]
|
|
|
|
}
|
|
|
|
key = str(ctx.message.guild.id)
|
|
|
|
if not await utils.add_content('tags', entry):
|
|
|
|
await utils.update_content('tags', {'tags': r.row['tags'].append(tag)}, key)
|
|
|
|
await ctx.send("I have just setup a new tag for this server! You can call your tag with {}".format(trigger))
|
|
|
|
|
2017-03-26 16:59:08 +13:00
|
|
|
@tag.command(name='edit', no_pm=True)
|
|
|
|
@utils.custom_perms(send_messages=True)
|
2017-03-26 17:00:30 +13:00
|
|
|
async def edit_tag(self, ctx, *, tag: str):
|
2017-03-26 16:59:08 +13:00
|
|
|
"""This will allow you to edit a tag that you have created
|
|
|
|
EXAMPLE: !tag edit this tag
|
|
|
|
RESULT: I'll ask what you want the new result to be"""
|
|
|
|
key = str(ctx.message.guild.id)
|
|
|
|
tags = await utils.get_content('tags', key)
|
|
|
|
def check(m):
|
|
|
|
return m.channel == ctx.message.channel and m.author == ctx.message.author and len(m.content) > 0
|
|
|
|
|
|
|
|
if tags and len(tags['tags']) > 0:
|
|
|
|
for i, t in enumerate(tags['tags']):
|
|
|
|
if t['trigger'] == tag:
|
|
|
|
if t['author'] == str(ctx.message.author.id):
|
|
|
|
my_msg = await ctx.send("Alright, what do you want the new result for the tag {} to be".format(tag))
|
|
|
|
try:
|
|
|
|
msg = await self.bot.wait_for("message", check=check, timeout=60)
|
|
|
|
except asyncio.TimeoutError:
|
|
|
|
await ctx.send("You took too long!")
|
|
|
|
return
|
|
|
|
new_tag = t.copy()
|
|
|
|
new_tag['result'] = msg.content
|
|
|
|
tags['tags'][i] = new_tag
|
|
|
|
try:
|
|
|
|
await my_msg.delete()
|
|
|
|
await msg.delete()
|
|
|
|
except discord.Forbidden:
|
|
|
|
pass
|
|
|
|
await utils.update_content('tags', tags, key)
|
|
|
|
await ctx.send("Alright, the tag {} has been updated".format(tag))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
await ctx.send("You can't edit someone else's tag!")
|
|
|
|
return
|
2017-03-26 17:02:47 +13:00
|
|
|
await ctx.send("There isn't a tag called {}!".format(tag))
|
2017-03-26 16:59:08 +13:00
|
|
|
else:
|
|
|
|
await ctx.send("There are no tags setup on this server!")
|
|
|
|
|
2016-07-23 23:59:02 +12:00
|
|
|
|
2017-03-08 11:35:30 +13:00
|
|
|
@tag.command(name='delete', aliases=['remove', 'stop'], no_pm=True)
|
2017-03-26 16:39:18 +13:00
|
|
|
@utils.custom_perms(send_messages=True)
|
2016-07-23 23:59:02 +12:00
|
|
|
async def del_tag(self, ctx, *, tag: str):
|
2016-09-29 12:39:34 +13:00
|
|
|
"""Use this to remove a tag from use for this server
|
2016-11-29 17:55:55 +13:00
|
|
|
Format to delete a tag is !tag delete <tag>
|
|
|
|
|
|
|
|
EXAMPLE: !tag delete stupid_tag
|
|
|
|
RESULT: Deletes that stupid tag"""
|
2017-03-26 16:45:39 +13:00
|
|
|
key = str(ctx.message.guild.id)
|
|
|
|
tags = await utils.get_content('tags', key)
|
2017-03-26 16:59:08 +13:00
|
|
|
if tags and len(tags['tags']) > 0:
|
2017-03-26 16:39:18 +13:00
|
|
|
for t in tags['tags']:
|
|
|
|
if t['trigger'] == tag:
|
2017-03-26 16:41:54 +13:00
|
|
|
if ctx.message.author.permissions_in(ctx.message.channel).manage_guild or str(ctx.message.author.id) == t['author']:
|
2017-03-26 16:39:18 +13:00
|
|
|
tags['tags'].remove(t)
|
2017-03-26 16:45:39 +13:00
|
|
|
await utils.update_content('tags', tags, key)
|
2017-03-26 16:42:56 +13:00
|
|
|
await ctx.send("I have just removed the tag {}".format(tag))
|
2017-03-26 16:39:18 +13:00
|
|
|
else:
|
|
|
|
await ctx.send("You don't own that tag! You can't remove it!")
|
|
|
|
return
|
2016-09-29 12:39:34 +13:00
|
|
|
else:
|
2017-03-26 16:39:18 +13:00
|
|
|
await ctx.send("There are no tags setup on this server!")
|
2016-07-24 00:01:16 +12:00
|
|
|
|
2016-07-31 12:20:55 +12:00
|
|
|
|
2016-07-24 00:01:16 +12:00
|
|
|
def setup(bot):
|
|
|
|
bot.add_cog(Tags(bot))
|