83 lines
3.3 KiB
Python
83 lines
3.3 KiB
Python
import json
|
|
import discord
|
|
import time
|
|
import os
|
|
from discord.ext import commands
|
|
# from discord.utils import get
|
|
from discord.ext.commands import has_permissions, CheckFailure
|
|
|
|
## Xeno Discord PY Bot
|
|
### verification
|
|
|
|
extname = 'Verification'
|
|
|
|
initcurtime = time.localtime()
|
|
curtime = (f'{initcurtime.tm_hour}{initcurtime.tm_min}{initcurtime.tm_sec}')
|
|
curdate = (f'{initcurtime.tm_year}{initcurtime.tm_mon}{initcurtime.tm_mday}')
|
|
# reactions = ['\U+26A0']
|
|
|
|
# Load in server verif channels json
|
|
with open("./data/verification/servers.json", "r") as serversjsonFile:
|
|
verifservers = json.load(serversjsonFile)
|
|
|
|
class Verification(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
|
|
# @commands.command(name='verify',description='verifies a user using roles to enter a server')
|
|
# async def verification(self, ctx):
|
|
# if (f'{ctx.message.guild.id}') in verifservers:
|
|
# print(f'{ctx.message.guild.id} was found in verifservers json')
|
|
# verifchannel = verifservers[f"{ctx.message.guild.id}"]
|
|
# else:
|
|
# print(f'{ctx.message.guild.id} was not found in verifservers json')
|
|
# verifchannel = "verification"
|
|
|
|
# verif_msg_id = ctx.message.id
|
|
|
|
# await ctx.message.add_reaction("⚠")
|
|
|
|
# @commands.Cog.listener()
|
|
# async def on_raw_reaction_add(self, payload):
|
|
# guild = self.bot.get_guild(payload.guild_id)
|
|
# role = discord.utils.get(guild.roles, name="Member")
|
|
# await payload.member.add_roles(role, reason=f"{payload.member.name} verified by Xeno (automated)", atomic=True)
|
|
# await payload.message.delete()
|
|
|
|
async def getVerificationCh(self, ctx):
|
|
for server in verifservers:
|
|
if (f'{ctx.message.guild.id}') in server:
|
|
print(f'{ctx.message.guild.id} was found in verifservers json')
|
|
verifchannel = verifservers[f"{ctx.message.guild.id}"]
|
|
else:
|
|
print(f'{ctx.message.guild.id} was not found in verifservers json')
|
|
verifchannel = "verification"
|
|
return verifchannel
|
|
|
|
async def telemLog(self, name, id, gname, gid):
|
|
#verification telemetry log
|
|
veriftelem = open("data/verification/verif.log", "a")
|
|
veriftelem.write(f"Cog_{extname}: successfully verified user {name} ({id}) in {gname} ({gid}) at {curtime} {curdate}")
|
|
veriftelem.close()
|
|
|
|
@commands.command(name="verify", description="verifies a user using roles to enter a server")
|
|
async def verifcmd(self, ctx):
|
|
# check if command was sent in non-verification channel, and don't do anything if so
|
|
verifchannel = self.getVerificationCh()
|
|
if ctx.channel.name not in verifchannel:
|
|
print("Message not sent in verification channel, temporary abort until i send a message.")
|
|
msgchannel = discord.utils.get(ctx.guild.channels, name=verifchannel)
|
|
msgchannelid = msgchannel.id
|
|
msgchannel.send(f"Test - your message wasn't sent in the verification channel of this server, {verifchannel}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# https://stackoverflow.com/questions/65127487/how-to-make-a-reaction-role-command-with-discord-py
|
|
|
|
async def setup(bot):
|
|
print(f'Cog_{extname} was initialized')
|
|
# await bot.add_cog(Verification(bot)) |