1
0
Fork 0

Add a calendar notify list command

This commit is contained in:
Ethanell 2020-05-28 14:32:34 +02:00
parent ae5f706cf5
commit 7c4bdfc1f3

View file

@ -3,7 +3,7 @@ from datetime import datetime, timedelta
import ics import ics
import requests import requests
from discord import Embed from discord import Embed, DMChannel, TextChannel
from discord.ext import commands from discord.ext import commands
from discord.ext import tasks from discord.ext import tasks
from discord.ext.commands import CommandNotFound, BadArgument, MissingRequiredArgument from discord.ext.commands import CommandNotFound, BadArgument, MissingRequiredArgument
@ -183,6 +183,22 @@ class Calendar(commands.Cog):
s.close() s.close()
await ctx.message.add_reaction("\U0001f44d") await ctx.message.add_reaction("\U0001f44d")
@calendar_notify.group("list")
@commands.guild_only()
async def calendar_notify_list(self, ctx: commands.Context):
s = db.Session()
embed = Embed(title="Notify list")
for c in s.query(db.Calendar).filter(db.Calendar.server == ctx.guild.id).all():
notify = []
for n in c.calendars_notify:
ch = self.bot.get_channel(n.channel)
if type(ch) == TextChannel:
notify.append(ch.mention)
elif type(ch) == DMChannel:
notify.append(ch.recipient.mention)
embed.add_field(name=c.name, value="\n".join(notify) or "Nothing here")
await ctx.send(embed=embed)
@calendar_notify.group("trigger", pass_context=True) @calendar_notify.group("trigger", pass_context=True)
@commands.guild_only() @commands.guild_only()
async def calendar_notify_trigger(self, ctx: commands.Context, name: str): async def calendar_notify_trigger(self, ctx: commands.Context, name: str):