Skip to content

Commit

Permalink
Merge pull request #7 from mik-at/patch-3
Browse files Browse the repository at this point in the history
Update oida.js
  • Loading branch information
akargl authored Feb 21, 2021
2 parents 4b42e2c + eac6353 commit 55757bc
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions commands/oida.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,54 @@ module.exports = {
return message.reply("Heast, wen soll i oidan?");
}

let lookupKey;
let username;
let targetusername;
let targetid;
let sourceid;
let oidacooldown;

if (message.mentions.users.size) {
const mentionedUser = message.mentions.users.first();
lookupKey = mentionedUser.id;
username = mentionedUser.username;
targetusername = mentionedUser.username;
targetid = mentionedUser.id;
} else {
username = args.join(" ");
lookupKey = username.toLowerCase();
targetusername = args.join(" ");
targetid = targetusername.toLowerCase();
}
sourceid = message.author.id;

let selfOidaChance = client.settings.selfOidaChance;
if (client.settings.selfOidaChancePerUser && client.settings.selfOidaChancePerUser.hasOwnProperty(message.author.id)) {
selfOidaChance = client.settings.selfOidaChancePerUser[message.author.id];
if (client.settings.oidaCooldown) {
oidacooldown = Date.now() + client.settings.oidaCooldown;
} else {
oidacooldown = Date.now() + 1800;
}

if (((client.settings.userIdsWithSelfOida && client.settings.userIdsWithSelfOida.includes(message.author.id))
|| !client.settings.userIdsWithSelfOida)
&& Math.random() <= selfOidaChance) {
lookupKey = message.author.id;
username = message.author.username;
if (this.oidaCount.hasOwnProperty(sourceid)) {
if (this.oidaCount[sourceid].lasttarget == targetid) {
return message.reply("Bist oag??!! Die selbe Person 2x oidan is verboten!");
}
} else {
this.oidaCount[sourceid] = { oidaCount: 0, lasttarget: "", lastsource: "", lasttime: 0 };
}

if (!this.oidaCount.hasOwnProperty(lookupKey)) {
this.oidaCount[lookupKey] = { oidaCount: 0 };
if(this.oidaCount.hasOwnProperty(targetid)) {
if ((this.oidaCount[targetid].lastsource == sourceid) && (this.oidaCount[targetid].lasttime > oidacooldown)) {
return message.reply("Zruckoidan spüts ned, sry");
}
if (this.oidaCount[targetid].lasttime > oidacooldown) {
return message.reply("NA!!! Den hauma grod erst geoidat, suach da wen andern zum sekkiern!");
}
} else {
this.oidaCount[targetid] = { oidaCount: 0, lasttarget: "", lastsource: "", lasttime: 0 };
}
this.oidaCount[lookupKey].oidaCount++;

this.oidaCount[targetid].oidaCount++;
this.oidaCount[targetid].lastsource = sourceid;
this.oidaCount[targetid].lasttime = Date.now();
this.oidaCount[sourceid].lasttarget = targetid;

fs.writeFileSync("oidacount.json", JSON.stringify(this.oidaCount, undefined, 4));

return message.channel.send(`Oida ${username}!\nDu wurdest ${this.oidaCount[lookupKey].oidaCount} mal geoidat.`);
return message.channel.send(`Oida ${targetusername}!\nDu wurdest ${this.oidaCount[targetid].oidaCount} mal geoidat.`);
},
oidaCount: {},
onLoad() {
Expand Down

0 comments on commit 55757bc

Please sign in to comment.