-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtagging.py
72 lines (59 loc) · 2.62 KB
/
tagging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import discord
import discord.emoji
from discord.ext import commands
from .data import Data
db = Data() # Initialize database
class Tagging(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.group(invoke_without_command=True)
async def tag(self, ctx, name=None):
if name:
result = db.taggingEntry.fetch(name, ctx.message.channel.id)
if result is None:
await ctx.send(f'Tag with identifier "{name}" does not exist.')
return
emb = discord.Embed()
emb.set_footer(text=f'\t\t\t\t\t\t\tTimestamp: {result["date"]}',
icon_url='https://avatars1.githubusercontent.com/u/42101452?s=200&v=4')
emb.add_field(name=f'{name}', value=result["content"], inline=False)
await ctx.send(embed=emb)
else:
result = db.taggingEntry.fetch_all(ctx.message.channel.id)
i = 0
if len(result) == 0:
await ctx.send(f'Tags in this channel "{ctx.channel.mention}" does not exist.')
return
emb = discord.Embed(title="Available tags for channel")
for entry in result:
emb.add_field(name=f'Tag', value=f'({i}:{entry["index"]}) ?tag {entry["name"]}', inline=False)
i += 1
await ctx.send(embed=emb)
@tag.command()
@commands.has_role("Library Developer")
async def add(self, ctx, name, *, content: str):
result = db.taggingEntry.fetch(name, ctx.message.channel.id)
# If Tag already exists, prevent duplicates
if result:
await ctx.send(f'Tag "{name}" already exists.')
return
db.taggingEntry.insert(ctx.message.channel.id, name, content, ctx.message.created_at)
await ctx.send(f'Tag "{name}" created.')
@tag.command()
@commands.has_role("Library Developer")
async def index(self, ctx, name: str):
result = db.taggingEntry.fetch(name, ctx.message.channel.id)
if result:
await ctx.send(f'Tag with identifier "{name}" has an index of "{result["index"]}"')
return
await ctx.send(f'Tag with identifier "{name}" does not exist.')
@tag.command()
@commands.has_role("Library Developer")
async def edit(self, ctx, id, *, newContent: str):
result = db.taggingEntry.update(id, content=newContent, date=ctx.message.created_at)
if result:
await ctx.send(f'Tag index of "{id}" updated successfully.')
return
await ctx.send(f'Tag index of "{id}" failed to update.')
def setup(bot):
bot.add_cog(Tagging(bot))