Add verification

god i hate this so much
This commit is contained in:
Ave Ozkal 2018-12-23 20:13:40 +03:00
parent 701d5ba084
commit fc7c0f89d6
No known key found for this signature in database
GPG key ID: 09356ABAA42C842B
4 changed files with 105 additions and 43 deletions

View file

@ -11,8 +11,9 @@ Based on https://gitlab.com/ao/dpybotbase
- [x] .py configs
- [x] membercount command
- [ ] Verification: Actual verification system
- [x] Verification: Actual verification system
- [x] Verification: Reset command
- [ ] Verification: Using log module from akbbot for logging attempts and removing old attempts
- [ ] Logging: joins
- [ ] Logging: leaves
- [ ] Logging: role changes

View file

@ -41,6 +41,7 @@ initial_extensions = ['cogs.common',
'cogs.admin',
'cogs.basic',
"cogs.err",
"cogs.verification",
'cogs.links',
'cogs.mod',
'cogs.meme']

View file

@ -5,6 +5,7 @@ import config
import random
from inspect import cleandoc
import config
import hashlib
welcome_header = """
@ -149,55 +150,113 @@ class Verification:
for x in welcome_footer:
await ctx.send(cleandoc(x))
@commands.guild_only()
@commands.command()
async def verify(self, ctx, *, verification_string: str):
"""Does verification.
async def process_message(self, message):
"""Big code that makes me want to shoot myself
Not really a rewrite but more of a port
See text on top of #verification for more info."""
Git blame tells me that I should blame/credit Robin Lambertz"""
if message.channel.id == config.welcome_channel:
# Assign common stuff into variables to make stuff less of a mess
member = message.author
full_name = str(member)
discrim = str(member.discriminator)
guild = message.guild
chan = message.channel
mcl = message.content.lower()
await ctx.message.delete()
# Get the role we will give in case of success
success_role = guild.get_role(config.participant_role)
veriflogs_channel = ctx.guild.get_channel(config.veriflogs_chanid)
verification_role = ctx.guild.get_role(config.read_rules_roleid)
verification_wanted = config.verification_code\
.replace("[discrim]", ctx.author.discriminator)
# Get a list of stuff we'll allow and will consider close
allowed_names = [f"@{full_name}", full_name, str(member.id)]
close_names = [f"@{member.name}", member.name, discrim,
f"#{discrim}"]
# Now add the same things but with newlines at the end of them
allowed_names += [(an + '\n') for an in allowed_names]
close_names += [(cn + '\n') for cn in close_names]
# Do checks on if the user can even attempt to verify
if ctx.channel.id != config.verification_chanid:
resp = await ctx.send("This command can only be used "
f"on <#{config.verification_chanid}>.")
await asyncio.sleep(config.sleep_secs)
return await resp.delete()
# Finally, hash the stuff so that we can access them later :)
sha1_allow = [hashlib.sha1(name.encode('utf-8')).hexdigest()
for name in allowed_names]
md5_allow = [hashlib.md5(name.encode('utf-8')).hexdigest()
for name in allowed_names]
sha1_close = [hashlib.sha1(name.encode('utf-8')).hexdigest()
for name in close_names]
if verification_role in ctx.author.roles:
resp = await ctx.send("This command can only by those without "
f"<@&{config.read_rules_roleid}> role.")
await asyncio.sleep(config.sleep_secs)
return await resp.delete()
# I'm not even going to attempt to break those into lines jfc
if any(allow in mcl for allow in sha1_allow):
await member.add_roles(success_role)
await chan.purge(limit=100, check=lambda m: m.author == message.author or (m.author == self.bot.user and message.author.mention in m.content))
elif any(close in mcl for close in sha1_close):
await chan.send(f"{message.author.mention} :no_entry: Close, but incorrect. You got the process right, but you're not doing it on your name and discriminator properly. Please re-read the rules carefully and look up any terms you are not familiar with.")
elif any(allow in mcl for allow in md5_allow):
await chan.send(f"{message.author.mention} :no_entry: Close, but incorrect. You're processing your name and discriminator properly, but you're not using the right process. Please re-read the rules carefully and look up any terms you are not familiar with.")
elif full_name in message.content or str(member.id) in message.content or member.name in message.content or discrim in message.content:
await chan.send(f"{message.author.mention} :no_entry: Incorrect. You need to do something with your name and discriminator instead of just posting it. Please re-read the rules carefully and look up any terms you are not familiar with.")
# Log verification attempt
await self.bot.update_logs("Verification Attempt",
ctx.author.id,
veriflogs_channel,
log_text=verification_string,
digdepth=50, result=-1)
async def on_message(self, message):
try:
await self.process_message(message)
except discord.errors.Forbidden:
chan = self.bot.get_channel(message.channel)
await chan.send("💢 I don't have permission to do this.")
# Check verification code
if verification_string.lower().strip() == verification_wanted:
resp = await ctx.send("Success! Welcome to the "
f"club, {str(ctx.author)}.")
await self.bot.update_logs("Verification Attempt",
ctx.author.id,
veriflogs_channel,
digdepth=50, result=0)
await asyncio.sleep(config.sleep_secs)
await ctx.author.add_roles(verification_role)
await resp.delete()
else:
resp = await ctx.send(f"Incorrect password, {str(ctx.author)}.")
await asyncio.sleep(config.sleep_secs)
await resp.delete()
async def on_message_edit(self, before, after):
try:
await self.process_message(after)
except discord.errors.Forbidden:
chan = self.bot.get_channel(after.channel)
await chan.send("💢 I don't have permission to do this.")
# @commands.guild_only()
# @commands.command()
# async def verify(self, ctx, *, verification_string: str):
# """Does verification.
# See text on top of #verification for more info."""
# await ctx.message.delete()
# veriflogs_channel = ctx.guild.get_channel(config.veriflogs_chanid)
# verification_role = ctx.guild.get_role(config.read_rules_roleid)
# verification_wanted = config.verification_code\
# .replace("[discrim]", ctx.author.discriminator)
# # Do checks on if the user can even attempt to verify
# if ctx.channel.id != config.verification_chanid:
# resp = await ctx.send("This command can only be used "
# f"on <#{config.verification_chanid}>.")
# await asyncio.sleep(config.sleep_secs)
# return await resp.delete()
# if verification_role in ctx.author.roles:
# resp = await ctx.send("This command can only by those without "
# f"<@&{config.read_rules_roleid}> role.")
# await asyncio.sleep(config.sleep_secs)
# return await resp.delete()
# # Log verification attempt
# await self.bot.update_logs("Verification Attempt",
# ctx.author.id,
# veriflogs_channel,
# log_text=verification_string,
# digdepth=50, result=-1)
# # Check verification code
# if verification_string.lower().strip() == verification_wanted:
# resp = await ctx.send("Success! Welcome to the "
# f"club, {str(ctx.author)}.")
# await self.bot.update_logs("Verification Attempt",
# ctx.author.id,
# veriflogs_channel,
# digdepth=50, result=0)
# await asyncio.sleep(config.sleep_secs)
# await ctx.author.add_roles(verification_role)
# await resp.delete()
# else:
# resp = await ctx.send(f"Incorrect password, {str(ctx.author)}.")
# await asyncio.sleep(config.sleep_secs)
# await resp.delete()
def setup(bot):

View file

@ -18,3 +18,4 @@ staff_role_ids = [526384077679624192, # Team role in NotSwitched
modlog_channel = 526377735908491284 # Log channel in NotSwitched
welcome_channel = 526372470752673792 # rules-info channel in NotSwitched
participant_role = 526378358129557506 # participant role in NotSwitched