forked from viveksantayana/geas-bot
Vivek Santayana
5bb9af12c9
Wrote up documentation. Readme needs finishing. Future development needs to use global listeners for processes.
46 lines
2.1 KiB
Python
46 lines
2.1 KiB
Python
import os # OS Locations
|
|
import yaml # YAML parser for Bot config files
|
|
import asyncio # Discord Py Dependency
|
|
import discord # Main Lib
|
|
from discord.ext import commands, tasks # Commands module
|
|
from discord_slash import SlashCommand, SlashContext, cog_ext, utils # Slash Command Library
|
|
from discord_slash.utils.manage_commands import create_choice, create_option # Slash Command features
|
|
from datetime import datetime
|
|
import logging
|
|
# logger and handler
|
|
from bot import configFile, yaml_load
|
|
|
|
#### Actions the bot will take on messages being sent in the channel.
|
|
|
|
##### Message Listener Cog
|
|
class on_message(commands.Cog, name='On Message Events'):
|
|
def __init__(self, client):
|
|
self.client = client
|
|
|
|
@commands.Cog.listener()
|
|
async def on_message(self,message):
|
|
if message.author.bot or message.author.id == message.guild.owner_id:
|
|
return
|
|
for role in message.author.roles:
|
|
if role.permissions.administrator:
|
|
return
|
|
conf = yaml_load(configFile)
|
|
guild = message.guild
|
|
guildStr = str(guild.id)
|
|
if 'notifications' in conf[guildStr]:
|
|
if conf[guildStr]['notifications'].get('help', False):
|
|
if 'help' in conf[guildStr]['channels'] and 'committee' in conf[guildStr]['roles']:
|
|
if message.channel.id == conf[guildStr]['channels']['help'] and isinstance(guild.get_role(conf[guildStr]['roles']['committee']), discord.Role):
|
|
modChannel = self.client.get_channel(conf[guildStr]['channels']['mod'])
|
|
committeeRole = guild.get_role(conf[guildStr]['roles']['committee'])
|
|
embed = discord.Embed(
|
|
title = f'[New Query in Help]({message.jump_url})',
|
|
description = message.content,
|
|
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 modChannel.send(f'{committeeRole.mention}\n```There has been a new help query posted.```\n{message.author.mention}` posted in `{message.channel.mention}`.`', embed = embed)
|
|
|
|
def setup(client):
|
|
client.add_cog(on_message(client)) |