Skip to content

Commit

Permalink
Added text file for ban command
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBThai committed Oct 3, 2021
1 parent 3915a86 commit fd43cc8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 45 deletions.
87 changes: 48 additions & 39 deletions src/commands/commandList/admin/prayfrom.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,59 @@ module.exports = new CommandInterface({
})

async function banList(p){
if(p.args[0]!="ban"){
p.errorMsg(", Invalid syntax! The correct use is `owo prayfrom ban {id} {minPrayCount}`",4000);
return;
}
let userid = p.args[1];
if(!p.global.isInt(userid)){
p.errorMsg(", Invalid user id!",3000);
return;
}
let min = p.args[2];
if(!p.global.isInt(min)){
p.errorMsg(", Invalid minimum pray count!",4000);
return;
}
if(p.args[0]!="ban"){
p.errorMsg(", Invalid syntax! The correct use is `owo prayfrom ban {id} {minPrayCount}`",4000);
return;
}
let userid = p.args[1];
if(!p.global.isInt(userid)){
p.errorMsg(", Invalid user id!",3000);
return;
}
let min = p.args[2];
if(!p.global.isInt(min)){
p.errorMsg(", Invalid minimum pray count!",4000);
return;
}

min = parseInt(min);
let user = await p.fetch.getUser(userid);
let username = user?user.username:userid;
min = parseInt(min);
let user = await p.fetch.getUser(userid);
let username = user?user.username:userid;

let sql = `SELECT receiver FROM user_pray WHERE sender = ${userid} AND count >= ${min};`;
let result = await p.query(sql);
if(!result||result.length==0){
p.errorMsg(", no users found",3000);
let sql = `SELECT receiver FROM user_pray WHERE sender = ${userid} AND count >= ${min};`;
let result = await p.query(sql);
if(!result||result.length==0){
p.errorMsg(", no users found",3000);
return;
}
let bans = [userid];
for(let i in result){
bans.push(result[i].receiver);
}
let count = bans.length;
const bansSql = "("+bans.join(",99999),(")+",99999)";
sql = `INSERT IGNORE INTO timeout (id,penalty) VALUES ${bansSql} ON DUPLICATE KEY UPDATE penalty = 99999;`;
await p.query(sql);

if(user){
try{
await (await user.getDMChannel()).createMessage("Your accounts has been banned for abusing pray/curse");
}catch(e){
p.replyMsg(banEmoji,", **"+username+"** and "+(count-1)+" users have been banned, I couldn't DM them.");
return;
}
let bans = [userid];
for(let i in result){
bans.push(result[i].receiver);
}
let count = bans.length;
bans = "("+bans.join(",99999),(")+",99999)";
sql = `INSERT IGNORE INTO timeout (id,penalty) VALUES ${bans} ON DUPLICATE KEY UPDATE penalty = 99999;`;
await p.query(sql);

if(user){
try{
await (await user.getDMChannel()).createMessage("Your accounts has been banned for abusing pray/curse");
}catch(e){
p.replyMsg(banEmoji,", **"+username+"** and "+(count-1)+" users have been banned, I couldn't DM them.");
return;
}
}
}

p.replyMsg(banEmoji,", **"+username+"** and "+(count-1)+" users have been banned");
let userList = '';
for (let i in bans) {
userList += bans[i] + ', ';
if ( !((parseInt(i) + 1) % 10) && i + 1 != bans.length) {
userList += '\n';
}
}
userList = userList.slice(0, -2);
const userListBuffer = Buffer.from(userList, 'utf8');
p.replyMsg(banEmoji,", **"+username+"** and "+(count-1)+" users have been banned", null, { file: userListBuffer, name: 'list.txt' });
}

async function displayList(p){
Expand Down
15 changes: 12 additions & 3 deletions src/commands/commandList/admin/prayto.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ async function banList(p){
bans.push(result[i].sender);
}
let count = bans.length;
bans = "("+bans.join(",99999),(")+",99999)";
sql = `INSERT IGNORE INTO timeout (id,penalty) VALUES ${bans} ON DUPLICATE KEY UPDATE penalty = 99999;`;
const bansSql = "("+bans.join(",99999),(")+",99999)";
sql = `INSERT IGNORE INTO timeout (id,penalty) VALUES ${bansSql} ON DUPLICATE KEY UPDATE penalty = 99999;`;
await p.query(sql);

if(user){
Expand All @@ -74,7 +74,16 @@ async function banList(p){
}
}

p.replyMsg(banEmoji,", **"+username+"** and "+(count-1)+" users have been banned");
let userList = '';
for (let i in bans) {
userList += bans[i] + ', ';
if ( !((parseInt(i) + 1) % 10) && i + 1 != bans.length) {
userList += '\n';
}
}
userList = userList.slice(0, -2);
const userListBuffer = Buffer.from(userList, 'utf8');
p.replyMsg(banEmoji,", **"+username+"** and "+(count-1)+" users have been banned", null, { file: userListBuffer, name: 'list.txt' });
}

async function displayList(p){
Expand Down
19 changes: 16 additions & 3 deletions src/utils/pubsubHandlers/banGuildMembers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,31 @@ exports.handle = async function(main, message){
if (!guild) return;

let memberIds = [];
let memberSql = [];
let memberCount = 0;
let log = '';
guild.members.forEach(member => {
memberIds.push(`(${member.id}, NOW(), 1, 999999)`);
memberIds.push(member.id);
memberSql.push(`(${member.id}, NOW(), 1, 999999)`);
log += member.id + ',';
memberCount++;
});
console.log(log);

const sql = `INSERT INTO timeout (id, time, count, penalty) VALUES ${memberIds.join(',')} ON DUPLICATE KEY UPDATE time = NOW(), count = count + 1, penalty = 999999;`;
const sql = `INSERT INTO timeout (id, time, count, penalty) VALUES ${memberSql.join(',')} ON DUPLICATE KEY UPDATE time = NOW(), count = count + 1, penalty = 999999;`;
await main.mysqlhandler.query(sql);

let userList = '';
for (let i in memberIds) {
userList += memberIds[i] + ', ';
if ( !((parseInt(i) + 1) % 10) && i + 1 != memberIds.length) {
userList += '\n';
}
}
userList = userList.slice(0, -2);
const buffer = Buffer.from(userList, 'utf8');

const msg = `${banEmoji} **|** Banned ${memberCount} members from **${guild.name}**.`
main.bot.createMessage(replyChannel, msg);
main.bot.createMessage(replyChannel, msg, { file: buffer, name: 'list.txt' });
}

0 comments on commit fd43cc8

Please sign in to comment.