geas-bot/app/cogs/HelpNotifier.py

48 lines
1.8 KiB
Python
Raw Normal View History

import discord
from discord.ext import commands, tasks
from datetime import datetime
def helpChannels(client):
l = []
for guild in client.guilds:
channel = discord.utils.find(lambda c: c.name == '⛑-help', guild.channels)
l.append(channel)
return l
def committeeRoles(client):
l = []
for guild in client.guilds:
role = discord.utils.find(lambda r: r.name == 'Committee', guild.roles)
l.append(role)
return l
def checkCommitteeRoles(author,committee):
if set(author.roles) & set(committee):
return True
class HelpNotifier(commands.Cog, name='Help Notifier Commands'):
def __init__(self,client):
self.client = client
# Message in Help channel event listener.
@commands.Cog.listener()
async def on_message(self,message):
if message.author.bot:
return
if checkCommitteeRoles(message.author, committeeRoles(self.client)):
return
if message.channel not in helpChannels(self.client):
return
committeeChannel = discord.utils.find(lambda t: t.name == '🗞-moderator-logs',message.guild.channels)
committeeRole = discord.utils.find(lambda c: c.name == 'Committee', message.guild.roles)
embed = discord.Embed(
title = message.content,
description = f'[Jump to Message]({message.jump_url})',
colour = discord.Colour.orange(),
)
embed.set_footer(text=datetime.now().strftime('%a %-d %b %y, %-I:%M %p'))
embed.set_author(name=message.author.display_name, icon_url=message.author.avatar_url)
await committeeChannel.send(f'Hey {committeeRole.mention}, {message.author.mention} has just posted the following message in the {message.channel.mention} channel', embed=embed)
def setup(client):
client.add_cog(HelpNotifier(client))