Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord bot switch to mumbai #822

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
3 changes: 2 additions & 1 deletion packages/diva-discord/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ https://discord.com/api/oauth2/authorize?client_id=960213520836862073&permission
start bot in powershell via:
- cd packages/diva-discord
#yarn hardhat run index.js --network ropsten
yarn hardhat run index.js --network goerli
#yarn hardhat run index.js --network goerli
yarn hardhat run index.js --network polygon_mumbai

extract list of users
- cd packages/diva-discord
Expand Down
1 change: 1 addition & 0 deletions packages/diva-discord/address.json

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions packages/diva-discord/checkIfInChannel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const Config = require('./config.json')

const Discord = require('discord.js');
const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_INTEGRATIONS
]});
var fs = require('fs');

async function checkServerMembership(guildId, userId) {
try {
const guild = await client.guilds.fetch(guildId);
const member = await guild.members.fetch(userId);
return member != null;
} catch (error) {
return false;
}
}

function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}

async function main() {
var users = JSON.parse(fs.readFileSync("users.json"));

const guildId = "928050978714976326"; // replace with your server ID
let i = 0;
while (i < users.length) {
const userId = users[i]; // replace with the user ID you want to check

const isMember = await checkServerMembership(guildId, userId);
fs.appendFile('ismember.txt', `${userId}; ${isMember}\r\n` , function (err) { });
sleep(500)
console.log(`The user is a member of the server: ${isMember}`);
i++
}
}

client.login(Config.TOKEN); // replace with your bot token

client.on("ready", async() => {
main();
})
24 changes: 12 additions & 12 deletions packages/diva-discord/commands/claim-test-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ module.exports = {
console.log(`Function claimtokens called by ${userName}`)

//check is user is already registered
if (dbRegisteredUsers.get(userId) == null) {
replyText = `Your discord account is not yet registered.\n `
+`Register with **/register ADDRESS**`
} else {
//next possible claim is 24h after last claim
const timeUntilNewClaim = new Date(dbRegisteredUsers.get(userId, "timestampLastClaim")).getTime() + 24 * 60 * 60 * 1000 - new Date()
if ( timeUntilNewClaim > 0 ){
replyText = `You can only claim tokens once per 24h.\n `
+`You need to wait ${new Date(timeUntilNewClaim).toISOString().slice(11,19)} before the next claim`
} else {
// if (dbRegisteredUsers.get(userId) == null) {
// replyText = `Your discord account is not yet registered.\n `
// +`Register with **/register ADDRESS**`
// } else {
// //next possible claim is 24h after last claim
// const timeUntilNewClaim = new Date(dbRegisteredUsers.get(userId, "timestampLastClaim")).getTime() + 24 * 60 * 60 * 1000 - new Date()
// if ( timeUntilNewClaim > 0 ){
// replyText = `You can only claim tokens once per 24h.\n `
// +`You need to wait ${new Date(timeUntilNewClaim).toISOString().slice(11,19)} before the next claim`
// } else {
addToSendQueue = true
if (interaction instanceof Discord.Interaction) {
await interaction.deferReply({ephemeral: true})
}
}
}
// }
// }

console.log(replyText);
if (replyText != ""){
Expand Down
70 changes: 70 additions & 0 deletions packages/diva-discord/fetchUsernames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

const Config = require('./config.json')

const fetch = require('node-fetch');

const userId = '312312999534788609'; // Replace this with the Discord ID that you want to retrieve the name for
const authToken = Config.TOKEN; // Replace this with your Discord Bot token

var fs = require('fs');
var users = JSON.parse(fs.readFileSync("users.json"));

let promises = [];

//users = ["893699769376059412","312312999534788609"]

function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}

async function queryUsers(start, end) {
while (i < end) {
let response= await fetch(`https://discord.com/api/v10/users/${users[i]}`, {
headers: {
Authorization: `Bot ${authToken}`
}
})
sleep(500)
data = await response.json()
sleep(500)
console.log(data);
const discordName = data.username;
fs.appendFile('mynewfile1.txt', `${data.id}; ${discordName}\r\n` , function (err) { });

/*.then(response => response.json())
.then(data => {


console.log(data)
console.log(`Discord name for user ${data.id}: ${discordName}`);

})
.catch(error => {
console.error(`Error retrieving Discord name for user : ${error}`);
fs.appendFile('mynewfile1.txt', `; error\r\n`, function (err) {

});
   });*/
i++
console.log(i)
}
}


let start =0;
let i = start;
console.log(users.length);

//321
queryUsers(start, users.length);
/*sleep(1000)
queryUsers(start+10);
sleep(1000)
queryUsers(start+20);
sleep(1000)
queryUsers(start+30);
*/
2 changes: 1 addition & 1 deletion packages/diva-discord/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = {
accounts: {
mnemonic: MNEMONIC,
},
gasPrice: 8000000000,
//gasPrice: 8000000000,
},
polygon: {
url: process.env.ALCHEMY_URL_POLYGON_MAINNET,
Expand Down
Loading
Loading