-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathverification.py
154 lines (130 loc) · 7.48 KB
/
verification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import os
import discord
from discord.ext import commands
from discord import utils
import requests
from .data import Data
import random
from datetime import datetime
from embed import footer_embed
db = Data() # Initialize database
available_words = ["apple", "orange", "pear", "boat", "ship", "car", "plane", "train", "turtle", "cow", "frog",
"sheep"] # Obstain from the number's 6 & 9 due to Roblox's filter
tempStorage = [] # Holds Random Keys
class Verification(commands.Cog):
def __init__(self, bot):
self.bot = bot
# Verification on member join
@commands.Cog.listener()
async def on_member_join(self, member):
channel = self.bot.get_channel(int(os.getenv("JOIN_LOGS_CHANNEL"))) # join-logs channel
role = utils.get(member.guild.roles, name="Verified")
response = requests.get(f'https://verify.eryn.io/api/user/{member.id}').json()
if response["status"] == "ok":
# Change nickname (Error if attempting to change server owner's nickname)
# Abort if already in database
result = db.verificationEntry.check_discordid(member.id)
if result:
await member.edit(nick=response["robloxUsername"])
await self.bot.add_roles(member, role)
await member.add_roles(role)
await channel.send(f'Verified "{member.mention}" as "{response["robloxUsername"]}" (current)')
return
db.verificationEntry.insert(member.id, response["robloxUsername"], response["robloxId"], datetime.now())
await member.edit(nick=response["robloxUsername"])
await member.add_roles(role)
await channel.send(f'Verified "{member.mention}" as "{response["robloxUsername"]}" 4')
else:
channel_dm = await member.create_dm()
await channel_dm.send(
f'It appears that you are not verified with RoVer or our own database. A keyphrase has been sent to '
f'your dms. Please verify w/ ``?verify`` in our server.')
@commands.command()
async def verify(self, ctx, username: str = None, *, keyPhrase: str = None):
member = ctx.message.author
role = utils.get(ctx.guild.roles, name="Verified")
channel = self.bot.get_channel(int(os.getenv("JOIN_LOGS_CHANNEL"))) # join-logs channel
response = requests.get(f'https://verify.eryn.io/api/user/{member.id}').json()
result = db.verificationEntry.check_discordid(member.id)
if result:
await member.edit(nick=response["robloxUsername"])
await member.add_roles(role)
await channel.send(f'Verified "{member.mention}" as "{response["robloxUsername"]}" (current)')
return
# Blank Verify (RoVer-based Method)
if username is None and keyPhrase is None:
if response["status"] == "ok":
# Change nickname (Error if attempting to change server owner's nickname)
db.verificationEntry.insert(member.id, response["robloxUsername"], response["robloxId"],
ctx.message.created_at)
await ctx.message.author.edit(nick=response["robloxUsername"])
await member.add_roles(role)
await ctx.send(f'Successfully verified as "{response["robloxUsername"]}" 3')
await channel.send(f'Verified "{member.mention}" as "{response["robloxUsername"]}" (current)')
else:
# User is not verified with RoVer Service; port to our own solution
channel = await member.create_dm()
temp_passphrase = ' '.join((random.choice(available_words) for i in range(8)))
tempStorage.append({
"discord_id": member.id,
"pass_phrase": temp_passphrase
})
await channel.send(
f'Here is your passphrase to verify. Please place this string of text (without quotes) "{temp_passphrase}" in your roblox profile blurb.')
await ctx.send(
f'It appears that you are not verified with RoVer or our own database. A keyphrase has been sent '
f'to your dms. Please reverify w/ ``?verify <username> <keyphrase>``')
# Custom Verify (Custom solution)
elif username and keyPhrase:
userid = requests.get(f'https://api.roblox.com/users/get-by-username?&username={username}').json()["Id"]
response_2 = requests.get(f'https://users.roblox.com/v1/users/{userid}/status').json()["status"]
for temps in tempStorage:
if temps["discord_id"] == member.id and temps["pass_phrase"] == response_2:
# Change nickname (Error if attempting to change server owner's nickname)
tempStorage.remove(temps)
db.verificationEntry.insert(member.id, username, userid, ctx.message.created_at)
await ctx.message.author.edit(nick=username)
await member.add_roles(role)
await ctx.send(f'Successfully verified as "{response_2["robloxUsername"]}" 2')
await channel.send(f'Verified "{member.mention}" as "{response_2["robloxUsername"]}" 5')
return
await ctx.send(f'Failed to verify as "{username}"')
@commands.command()
async def info(self, ctx, member: discord.Member):
# Fetch data from database
query = db.verificationEntry.fetch(member.id)
# If no data exists for user, abort
if not query:
await ctx.send(f'User "{member.id}" is not verified.')
return
emb = footer_embed(ctx.message, 'Information')
emb.add_field(name=f'**{member.display_name}**',
value=f'Discord Id: {query["discordid"]}\nUsername: {query["username"]}\nUser Id: {query["userid"]}\nDate: {query["date"]}',
inline=False)
emb.add_field(name=f'Profile', value=f'https://www.roblox.com/users/{query["userid"]}/profile', inline=False)
await ctx.send(embed=emb)
@commands.command()
@commands.has_role("Moderator")
async def force_verify(self, ctx, username, member: discord.Member):
role = utils.get(ctx.guild.roles, name="Verified")
userid = requests.get(f'https://api.roblox.com/users/get-by-username?&username={username}').json()["Id"]
channel = self.bot.get_channel(int(os.getenv("JOIN_LOGS_CHANNEL"))) # join-logs channel
# Prevent overwrite
result = db.verificationEntry.check_discordid(member.id)
if result:
await member.edit(nick=username)
await member.add_roles(role)
await ctx.send(f'Successfully forced verified "{username}" as "{member.mention}" (current)')
await channel.send(f'Successfully forced verified "{username}" as "{member.mention}" (current)')
return
db.verificationEntry.insert(member.id, username, userid, ctx.message.created_at)
await member.edit(nick=username)
await member.add_roles(role)
await ctx.send(f'Successfully forced verified "{username}" as "{member.mention}" 1')
await channel.send(f'Successfully forced verified "{username}" as "{member.mention}"')
@commands.command()
@commands.has_role("Moderator")
async def verify_check(self, ctx, member: discord.Member):
await ctx.send(db.verificationEntry.check_discordid(member.id))
def setup(bot):
bot.add_cog(Verification(bot))