mirror of
https://github.com/janderedev/automod.git
synced 2024-12-22 10:45:27 +00:00
woops lol
This commit is contained in:
parent
bc10c3d014
commit
cbde4e4c40
|
@ -86,33 +86,36 @@ client.on('message', async message => {
|
||||||
|
|
||||||
// DM message based API session token retrieval
|
// DM message based API session token retrieval
|
||||||
client.on('message', async message => {
|
client.on('message', async message => {
|
||||||
console.log(message.channel?.channel_type, message.nonce, message.content)
|
try {
|
||||||
if (
|
if (
|
||||||
message.channel?.channel_type == "DirectMessage" &&
|
message.channel?.channel_type == "DirectMessage" &&
|
||||||
message.nonce?.startsWith("REQUEST_SESSION_TOKEN-") &&
|
message.nonce?.startsWith("REQUEST_SESSION_TOKEN-") &&
|
||||||
message.content?.toLowerCase().startsWith("requesting session token.")
|
message.content?.toLowerCase().startsWith("requesting session token.")
|
||||||
) {
|
) {
|
||||||
logger.info('Received session token request in DMs.');
|
logger.info('Received session token request in DMs.');
|
||||||
|
|
||||||
const token = crypto.randomBytes(48).toString('base64').replace(/=/g, '');
|
const token = crypto.randomBytes(48).toString('base64').replace(/=/g, '');
|
||||||
|
|
||||||
await client.db.get('sessions').insert({
|
await client.db.get('sessions').insert({
|
||||||
user: message.author_id,
|
user: message.author_id,
|
||||||
token: token,
|
token: token,
|
||||||
nonce: message.nonce,
|
nonce: message.nonce,
|
||||||
invalid: false,
|
invalid: false,
|
||||||
expires: Date.now() + DM_SESSION_LIFETIME,
|
expires: Date.now() + DM_SESSION_LIFETIME,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Don't need to risk exposing the user to the token, so we'll send it in the nonce
|
// Don't need to risk exposing the user to the token, so we'll send it in the nonce
|
||||||
await message.channel.sendMessage({
|
await message.channel.sendMessage({
|
||||||
content: 'Token request granted.',
|
content: 'Token request granted.',
|
||||||
nonce: `${ulid()}; TOKEN:${token}`,
|
nonce: `${ulid()}; TOKEN:${token}`,
|
||||||
replies: [ { id: message.author_id, mention: false } ],
|
replies: [ { id: message._id, mention: false } ],
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
// Send a message when added to a server
|
// Send a message when added to a server
|
||||||
client.on('member/join', (member) => {
|
client.on('member/join', (member) => {
|
||||||
|
|
Loading…
Reference in a new issue