Skip to content

Instantly share code, notes, and snippets.

@gsquaredxc
Created July 18, 2020 07:01
Show Gist options
  • Save gsquaredxc/2441f297979c0f5da5846a15ca0951be to your computer and use it in GitHub Desktop.
Save gsquaredxc/2441f297979c0f5da5846a15ca0951be to your computer and use it in GitHub Desktop.
import os
import discord
from dotenv import load_dotenv
from discord.ext import commands
import config as conf
from messageWeight import message_weigher
from userPerms import has_admin_perms
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
conf.open_conf()
bot = commands.Bot(command_prefix="%")
@bot.command(name='config')
async def config(ctx, arg1, arg2):
print("o/")
if has_admin_perms(ctx.author):
conf.Config[str(ctx.guild.id)][arg1] = arg2
return
@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
global global_channel
global_channel = bot.get_channel(733897610716381256)
@bot.event
async def on_message(message):
if message.author == bot.user:
return
elif message.content == "%init":
if has_admin_perms(message.author):
conf.Config[str(message.guild.id)] = conf.Config["baseConfig"]
return
else:
#weight = message_weigher(message)
weight = 0 #TODO
if weight >= conf.Config[str(message.guild.id)]["report_to_all"] or weight >= \
conf.Config[str(message.guild.id)]["report_to_spam_channel"]:
embedVar = discord.Embed(title="Suspicious message", color=0x00ff00)
embedVar.add_field(name="Message content:", value=message.content, inline=False)
embedVar.add_field(name="Message weight:", value=str(weight), inline=False)
embedVar.add_field(name="Author:", value=message.author.mention, inline=True)
embedVar.add_field(name="Full name:", value=str(message.author), inline=True)
embedVar.add_field(name="ID:", value=message.author.id, inline=False)
embedVar.add_field(name="Author age:", value=message.author.created_at, inline=True)
if weight >= conf.Config[str(message.guild.id)]["report_to_all"]:
await global_channel.send(embed=embedVar)
if weight >= conf.Config[str(message.guild.id)]["report_to_spam_channel"]:
await bot.get_channel(int(conf.Config[str(message.guild.id)]["spam_channel"])).send(embed=embedVar)
if weight >= conf.Config[str(message.guild.id)]["mute"]:
pass # TODO
return
try:
bot.run(TOKEN)
except BaseException as e: # Catches keyboard interrupt
print(e)
finally:
print("Saving config")
conf.save_conf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment