Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CSLib The Authmaster
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Amalia Filip
CSLib The Authmaster
Commits
3966d42d
Commit
3966d42d
authored
4 years ago
by
amy
Browse files
Options
Downloads
Patches
Plain Diff
First prototype
parent
f6026f82
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
__pycache__/msgTemplates.cpython-37.pyc
+0
-0
0 additions, 0 deletions
__pycache__/msgTemplates.cpython-37.pyc
bot.py
+37
-11
37 additions, 11 deletions
bot.py
msgTemplates.py
+17
-6
17 additions, 6 deletions
msgTemplates.py
with
54 additions
and
17 deletions
__pycache__/msgTemplates.cpython-37.pyc
+
0
−
0
View file @
3966d42d
No preview for this file type
This diff is collapsed.
Click to expand it.
bot.py
+
37
−
11
View file @
3966d42d
import
discord
,
asyncio
import
os
,
sys
,
string
,
random
import
os
,
sys
,
string
,
random
,
time
import
msgTemplates
,
utils
def
getPath
():
return
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
# Maybe move these to a config?
cslibServerID
=
763446305006682142
memberRoleID
=
763872584408104960
version
=
"
0.1
"
prefix
=
"
!
"
client
=
discord
.
Client
()
registrationDb
=
{}
registrationUserTimeout
=
{}
@client.event
async
def
on_message
(
message
):
...
...
@@ -22,31 +25,54 @@ async def on_message (message):
command
[
0
]
=
command
[
0
].
lower
()
# We are in a private chat
if
(
type
(
message
.
channel
)
is
discord
.
DMChannel
):
if
(
type
(
message
.
channel
)
is
not
discord
.
DMChannel
):
if
(
command
[
0
]
==
"
help
"
):
outMsg
=
msgTemplates
.
helpHeader
.
format
(
version
)
for
cmd
in
msgTemplates
.
helpMain
:
outMsg
+=
"
\t
- **{}**: `{}`
\n
"
.
format
(
cmd
,
msgTemplates
.
helpMain
[
cmd
])
return
await
message
.
channel
.
send
(
outMsg
)
else
:
if
(
command
[
0
]
==
"
help
"
):
outMsg
=
msgTemplates
.
helpHeader
.
format
(
version
)
for
cmd
in
msgTemplates
.
helpDm
:
outMsg
+=
"
\t
- **{}**: `{}`
\n
"
.
format
(
cmd
,
msgTemplates
.
helpDm
[
cmd
])
return
await
message
.
channel
.
send
(
outMsg
)
if
(
command
[
0
]
==
"
register
"
):
if
(
len
(
command
)
==
1
):
return
await
message
.
channel
.
send
(
msgTemplates
.
usageRegister
)
email
=
command
[
1
].
strip
()
if
(
not
utils
.
validateMail
(
email
)):
return
await
message
.
channel
.
send
(
msgTemplates
.
i
nvalidMail
.
format
(
email
))
return
await
message
.
channel
.
send
(
msgTemplates
.
errorI
nvalidMail
.
format
(
email
))
verificationCode
=
''
.
join
(
random
.
choices
(
string
.
ascii_lowercase
+
string
.
digits
,
k
=
16
))
registrationDb
[
verificationCode
]
=
message
.
author
.
id
try
:
utils
.
sendMail
(
email
,
msgTemplates
.
v
alid
ationMailTextBody
.
format
(
email
,
verificationCode
))
utils
.
sendMail
(
email
,
msgTemplates
.
v
erific
ationMailTextBody
.
format
(
email
,
verificationCode
))
except
:
return
await
message
.
channel
.
send
(
msgTemplates
.
errorMail
)
await
message
.
channel
.
send
(
msgTemplates
.
v
alid
ationMailSent
.
format
(
email
))
await
message
.
channel
.
send
(
msgTemplates
.
v
erific
ationMailSent
.
format
(
email
))
if
(
command
[
0
]
==
"
verify
"
):
if
(
command
[
1
]
in
registrationDb
):
userId
=
registrationDb
[
command
[
1
]]
guild
=
await
client
.
fetch_guild
(
cslibServerID
)
user
=
await
guild
.
get_member
(
userId
)
await
user
.
edit
(
roles
=
[
await
guild
.
get_role
(
memberRoleID
)])
if
(
len
(
command
)
==
1
):
return
await
message
.
channel
.
send
(
msgTemplates
.
usageVerify
)
verificationCode
=
command
[
1
]
if
(
verificationCode
in
registrationDb
):
userId
=
registrationDb
[
verificationCode
]
guild
=
client
.
get_guild
(
cslibServerID
)
await
guild
.
get_member
(
userId
).
edit
(
roles
=
[
guild
.
get_role
(
memberRoleID
)])
registrationDb
.
pop
(
verificationCode
,
None
)
await
message
.
channel
.
send
(
msgTemplates
.
userVerified
)
else
:
await
message
.
channel
.
send
(
msgTemplates
.
errorVerificationCode
.
format
(
command
[
1
]))
...
...
This diff is collapsed.
Click to expand it.
msgTemplates.py
+
17
−
6
View file @
3966d42d
verification
=
"""
:gear: Welcome to **CSLib** :gear:
I will first need to verify your account! Send me your `@soton.ac.uk` university e-mail address by using: `!register YOUR-ID@soton.ac.uk`
I will then send you an e-mail with a
n authent
ication code. Send it to back to me as such: `!verify
AUTH-CODE
` and get verified!
"""
I will then send you an e-mail with a
verif
ication code. Send it to back to me as such: `!verify
verification-code
` and get verified!
"""
invalidMail
=
"
`{}` is an invalid `@soton.ac.uk` e-mail
"
validationMailSent
=
"
Sent verification e-mail to: `{}`
"
validationMailTextBody
=
"""
From: CSLib Authmaster <cslibdiscordbot@gmail.com>
helpHeader
=
"
:gear: **CSLib** Authmaster v{} :gear:
\n
"
helpDm
=
{
"
!register YOUR-ID@soton.ac.uk
"
:
"
Send a verification code to your Southampton e-mail address
"
,
"
!verify AUTH-CODE
"
:
"
Verify your discord account with the verification code received via e-mail
"
}
helpMain
=
{
"
!help
"
:
"
Show this message
"
}
verificationMailSent
=
"
Sent verification e-mail to: `{}`
"
verificationMailTextBody
=
"""
From: CSLib Authmaster <cslibdiscordbot@gmail.com>
To: CSLib Apprentice <{}>
Subject: CSLib Verification
Your CSLib verification code is: {}
"""
userVerified
=
"
You have been verified! Welcome to the CSLib community.
"
errorMail
=
"
There has been an error sending an e-mail. Please contact the CSLib Managers!
"
errorMail
=
"
There has been an error sending an e-mail. If you think this is a problem, please contact a CSLib Manager!
"
errorInvalidMail
=
"
`{}` is an invalid `@soton.ac.uk` e-mail
"
errorVerificationCode
=
"
Invalid verification code: `{}`
"
usageRegister
=
"
Usage: !register YOUR-ID@soton.ac.uk
"
\ No newline at end of file
usageRegister
=
"
Usage: !register `YOUR-ID@soton.ac.uk`
"
usageVerify
=
"
Usage: !verify `verification-code`
"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment