-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (50 loc) · 1.93 KB
/
index.js
File metadata and controls
66 lines (50 loc) · 1.93 KB
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
const {Client, Events, GatewayIntentBits} = require('discord.js')
const { token } = require('./.config.json');
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); // for the button in verify
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
//part 2
const {ButtonHandler} = require('./EventHandling/button.js');
verificationQueue = {}// will contain all the users which are in the queue to be verified
//database intialization
const DataStore=require('nedb');
var db = new DataStore({
filename:'database.db',
autoload:true
});
console.log("database initialized");
client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
sendVerifyMessage();
ButtonHandler(client,verificationQueue,db); // handles request to verify
});
async function sendVerifyMessage(){
const allGuilds = await client.guilds.fetch(); // map object (Snowflake,OAuth2 guild)
// iterate through all OuthA2guilds now
allGuilds.forEach(async function(value,key,map){
var curGuild = await value.fetch(); // fetches guild structure
// iterating through channels
allChannels = await curGuild.channels.fetch();
allChannels.forEach(async function(value,key,map){
var curChannel = value;
if (curChannel.type!=0 || curChannel.name!="wallet_verification")
return;
// type 0 is for Guild Text based channels
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('primary')
.setLabel('verify!')
.setStyle(ButtonStyle.Primary),
);
// check message history
if((await curChannel.messages.fetch()).size==0){ // no verification messages have been sent earlier
curChannel.send({content:'click to verify your wallet',components:[row]});
}
//for testing delete all current messages and then send a new one
// console.log((await curChannel.messages.fetch()))
});
});
}
// part 2
// function logs into
client.login(token);