Update events.py

This commit is contained in:
Elmon11 2020-10-30 14:57:14 +01:00 committed by GitHub
parent 6f7d3e84aa
commit 471f10a1f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,18 @@
import discord import discord
import random
import aiofiles import aiofiles
import re import re
import time
import telnet
from datetime import datetime from datetime import datetime
from discord.ext import commands from discord.ext import commands
from checks import * from checks import *
from functions import * from functions import *
from unicode import *
class Events(commands.Cog): class Events(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@ -35,6 +41,8 @@ class Events(commands.Cog):
global starttime global starttime
starttime = datetime.utcnow() starttime = datetime.utcnow()
@commands.Cog.listener() @commands.Cog.listener()
async def on_message(self, message): async def on_message(self, message):
if message.guild and message.author is message.guild.me and message.channel.id == reports_channel_id: if message.guild and message.author is message.guild.me and message.channel.id == reports_channel_id:
@ -45,9 +53,22 @@ class Events(commands.Cog):
await message.delete() await message.delete()
bypass_roles = [discord_admin, discord_mod] bypass_roles = [discord_admin, discord_mod]
bypass = False bypass = False
if message.author != self.bot.user:
for role in message.author.roles: for role in message.author.roles:
if role.id in bypass_roles: if role.id in bypass_roles:
bypass = True bypass = True
else:
if 'Server has started' in message.content: # Telnet reconnect script
try:
telnet.connect()
except Exception as e:
print('Failed to reconnect telnet: {e}')
time.sleep(5)
try:
telnet.connect()
except Exception as fuckup:
print('Second attempt failed to reconnect telnet: {fuckup}')
if not bypass: if not bypass:
if re.search('discord\.gg\/[a-zA-z0-9\-]{1,16}', message.content) or re.search('discordapp\.com\/invite\/[a-z0-9]+/ig', message.content): if re.search('discord\.gg\/[a-zA-z0-9\-]{1,16}', message.content) or re.search('discordapp\.com\/invite\/[a-z0-9]+/ig', message.content):
await message.delete() await message.delete()
@ -114,6 +135,9 @@ class Events(commands.Cog):
@commands.Cog.listener() @commands.Cog.listener()
async def on_command_completion(self, ctx): async def on_command_completion(self, ctx):
print(f'[{datetime.utcnow().replace(microsecond=0)} INFO]: [Commands] {ctx.author} ran: {ctx.message.content} in guild: {ctx.guild.name}') print(f'[{datetime.utcnow().replace(microsecond=0)} INFO]: [Commands] {ctx.author} ran: {ctx.message.content} in guild: {ctx.guild.name}')
bot_logs_channel = self.bot.get_channel(bot_logs_channel_id)
log = discord.Embed(title='Logging', description=f'{ctx.author} (ID: {ctx.author.id}) ran: {ctx.message.content}', colour=0xA84300)
await bot_logs_channel.send(embed=log)
@commands.Cog.listener() @commands.Cog.listener()
async def on_raw_reaction_add(self, payload): async def on_raw_reaction_add(self, payload):