-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62045f1
commit 534592e
Showing
14 changed files
with
457 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
.env | ||
node_modules | ||
database.sqlite | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,57 @@ | ||
const fs = require ('fs'); | ||
const fs = require('fs'); | ||
const fetch = require('node-fetch'); | ||
module.exports = { | ||
name:'addgame', | ||
aliases:['ag'], | ||
usage:'<website-name|id>', | ||
description:'adds the game you want to see its runs to the gamelist', | ||
async execute(message,args){ | ||
if(message.guild&&!message.member.permissions.has("MANAGE_MESSAGES")) return message.reply('only staff can change game'); | ||
name: 'addgame', | ||
aliases: ['ag'], | ||
usage: '<website-name|id>', | ||
description: 'adds the game you want to see its runs to the gamelist', | ||
async execute(message, args, Guild, Game) { | ||
if (message.guild && !message.member.permissions.has("MANAGE_MESSAGES")) return message.reply('only staff can change game'); | ||
const input = args.join('%20') | ||
const errormsg = "please input a valid name, abbreviation or id"; | ||
const res = await fetch(`https://www.speedrun.com/api/v1/games/${input}`); | ||
const res = await fetch(`https://www.speedrun.com/api/v1/games/${input}`); | ||
let json = await res.json(); | ||
if(!json.data){ | ||
|
||
if (!json.data) { | ||
const ares = await fetch(`https://www.speedrun.com/api/v1/games?name=${input}`); | ||
let ajson = await ares.json(); | ||
if(!ajson.data) return message.reply(errormsg); | ||
if(ajson.data[0]){ | ||
json.data = ajson.data.find(x => x.names.international == args.join(" ")) | ||
if(!json.data) return message.reply(errormsg); | ||
} else { | ||
json = ajson; | ||
let ajson = await ares.json(); | ||
if (!ajson.data) return message.reply(errormsg); | ||
if (ajson.data[0]) { | ||
json.data = ajson.data.find(x => x.names.international == args.join(" ")) | ||
if (!json.data) return message.reply(errormsg); | ||
} else { | ||
json = ajson; | ||
|
||
if(!json.data.id) return message.reply(errormsg); | ||
if (!json.data.id) return message.reply(errormsg); | ||
} | ||
} | ||
} | ||
const content = await fs.promises.readFile('./storage.json'); | ||
const storageObject = JSON.parse(content); | ||
let objtype = message.guild?message.guild.id:message.author.id; | ||
|
||
const obj = { id : json.data.id, name : json.data.names.international, url:json.data.assets['cover-large'].uri}; | ||
const serverObject = storageObject[objtype]; | ||
|
||
if(serverObject && serverObject.find(x => x.id == json.data.id)) return message.reply('i can\'t add a game thats already in the list'); | ||
|
||
if (storageObject[objtype] instanceof Array) { | ||
storageObject[objtype].push(obj); | ||
} else { | ||
storageObject[objtype] = [ obj ]; | ||
} | ||
await fs.promises.writeFile('./storage.json', JSON.stringify(storageObject)); | ||
// const content = await fs.promises.readFile('./storage.json'); | ||
// const storageObject = JSON.parse(content); | ||
const [game,] = await Game.findOrCreate({ | ||
where: { | ||
id: json.data.id | ||
}, | ||
defaults: { | ||
name: json.data.names.international, | ||
url: json.data.assets['cover-large'].uri | ||
} | ||
}), | ||
[guild,] = await Guild.findOrCreate({ | ||
where: { | ||
id: message.guild ? message.guild.id : message.author.id | ||
}, | ||
defaults: { | ||
channel: message.guild && message.guild.channels.cache.find(x => x.name == "new-runs")?.id || null, | ||
isUser: !message.guild | ||
} | ||
}), | ||
isGameInGuild = await guild?.hasGame(game); | ||
if (isGameInGuild) return message.reply('i can\'t add a game thats already in the list'); | ||
await guild.addGame(game); | ||
// if (storageObject[objtype] instanceof Array) { | ||
// storageObject[objtype].push(obj); | ||
// } else { | ||
// storageObject[objtype] = [obj]; | ||
// } | ||
message.channel.send(`the game ${json.data.names.international} has been successfully added to the runlist`); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,44 @@ | ||
const fetch = require('node-fetch'); | ||
const fs = require ('fs'); | ||
const fs = require('fs'); | ||
module.exports = { | ||
name:'deletegame', | ||
aliases:['dg'], | ||
usage:'<website-name|id>', | ||
description:'delete the game you don\'t want to see its runs from the gamelist', | ||
async execute(message,args){ | ||
if(message.guild&&!message.member.permissions.has("MANAGE_MESSAGES")) return message.reply('only staff can change game'); | ||
const input = args.join("%20") | ||
const res = await fetch(`https://www.speedrun.com/api/v1/games/${input}`); | ||
let json = await res.json(); | ||
if(!json.data){ | ||
|
||
name: 'deletegame', | ||
aliases: ['dg'], | ||
usage: '<website-name|id>', | ||
description: 'delete the game you don\'t want to see its runs from the gamelist', | ||
async execute(message, args, Guild, Game) { | ||
if (message.guild && !message.member.permissions.has("MANAGE_MESSAGES")) return message.reply('only staff can change game'); | ||
const [guild,] = await Guild.findOrCreate({ | ||
where: { | ||
id: message.guild ? message.guild.id : message.author.id | ||
}, | ||
defaults: { | ||
channel: message.guild && message.guild.channels.cache.find(x => x.name == "new-runs")?.id || null, | ||
isUser: !message.guild | ||
} | ||
}); | ||
const input = args.join("%20") | ||
const res = await fetch(`https://www.speedrun.com/api/v1/games/${input}`); | ||
let json = await res.json(); | ||
if (!json.data) { | ||
const ares = await fetch(`https://www.speedrun.com/api/v1/games?name=${input}`); | ||
let ajson = await ares.json(); | ||
if(!ajson.data) return message.reply('please input a valid name, abbreviation or id'); | ||
if(ajson.data[0]){ | ||
json.data = ajson.data.find(x => x.names.international == args.join(" ")) | ||
if(!json.data) return message.reply('please input a valid name, abbreviation or id'); | ||
} else { | ||
json = ajson; | ||
let ajson = await ares.json(); | ||
if (!ajson.data) return message.reply('please input a valid name, abbreviation or id'); | ||
if (ajson.data[0]) { | ||
json.data = ajson.data.find(x => x.names.international == args.join(" ")) | ||
if (!json.data) return message.reply('please input a valid name, abbreviation or id'); | ||
} else { | ||
json = ajson; | ||
} | ||
} | ||
} | ||
const objtype = message.guild?message.guild.id:message.author.id; | ||
const content = await fs.promises.readFile('./storage.json'); | ||
const storageObject = JSON.parse(content); | ||
const list = storageObject[objtype] | ||
|
||
if(!list) return message.reply('i can\'t delete a game from a list thats empty'); | ||
if(!list.find(x => x.id == json.data.id)) return message.reply('i can\'t delete a game thats not in the list') | ||
storageObject[objtype] = list.filter(x => x.id != json.data.id) | ||
|
||
await fs.promises.writeFile('./storage.json', JSON.stringify(storageObject)); | ||
|
||
|
||
|
||
const game = await Game.findOne({ | ||
where: { | ||
id: json.data.id | ||
} | ||
}); | ||
if(!game) return message.reply('i can\'t delete a game that never got added'); | ||
const isGameInGuild = guild.hasGame(game); | ||
if (!isGameInGuild) return message.reply('i can\'t delete a game thats not in the list'); | ||
guild.removeGame(game) | ||
message.channel.send(`the game ${json.data.names.international} got successfully deleted`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,66 @@ | ||
const fs = require ('fs'); | ||
const fs = require('fs'); | ||
const fetch = require('node-fetch'); | ||
module.exports = { | ||
name:'deletegames', | ||
aliases:['ags'], | ||
usage:'<website-name|id>', | ||
description:'deletes the games you don\'t want to see their runs to the gamelist', | ||
async execute(message,args){ | ||
if(message.guild&&!message.member.permissions.has("MANAGE_MESSAGES")) return message.reply('only staff can change game'); | ||
let argz = args.join(' ').split('|'); | ||
argz = argz.map(x => x.replace(' ','%20')); | ||
const content = await fs.promises.readFile('./storage.json'); | ||
const storageObject = JSON.parse(content); | ||
const objtype = message.guild?message.guild.id:message.author.id | ||
name: 'deletegames', | ||
aliases: ['ags'], | ||
usage: '<website-name|id>', | ||
description: 'deletes the games you don\'t want to see their runs to the gamelist', | ||
async execute(message, args, Guild, Game) { | ||
if (message.guild && !message.member.permissions.has("MANAGE_MESSAGES")) return message.reply('only staff can change game'); | ||
let argz = args.join(' ').split('|'), | ||
games = []; | ||
argz = argz.map(x => x.replace(' ', '%20')); | ||
const [guild,] = await Guild.findOrCreate({ | ||
where: { | ||
id: message.guild ? message.guild.id : message.author.id | ||
}, | ||
defaults: { | ||
channel: message.guild && message.guild.channels.cache.find(x => x.name == "new-runs")?.id || null, | ||
isUser: !message.guild | ||
} | ||
}); | ||
|
||
for(const x of argz){ | ||
x = x.trim(); | ||
const errormsg = `are you sure https://www.speedrun.com/${x} exists | ||
||if it didn't work try deleting unnecessary spaces||`; | ||
for (const x of argz) { | ||
x = x.trim(); | ||
const errormsg = `are you sure https://www.speedrun.com/${x} exists\n||if it didn't work try deleting unnecessary spaces||`; | ||
const res = await fetch(`https://www.speedrun.com/api/v1/games/${x}`); | ||
let json = await res.json(); | ||
if(!json.data){ | ||
|
||
const ares = await fetch(`https://www.speedrun.com/api/v1/games?name=${x}`); | ||
let ajson = await ares.json(); | ||
if(!ajson.data){ | ||
message.reply(errormsg) | ||
continue; | ||
} | ||
if(ajson.data[0]){ | ||
json.data = ajson.data.find(y => y.names.international == x.replace('%20',' ')); | ||
if(!json.data){ | ||
message.reply(errormsg); | ||
continue; | ||
} | ||
} else { | ||
json = ajson; | ||
} | ||
} | ||
const list = storageObject[objtype]; | ||
let json = await res.json(); | ||
if (!json.data) { | ||
|
||
if(!list){ | ||
message.reply('i can\'t delete a game from a list thats empty'); | ||
continue; | ||
} | ||
if(!list.find(y => y.id == json.data.id)){ | ||
message.reply('i can\'t delete a game thats not in the list'); | ||
continue; | ||
} | ||
storageObject[objtype] = list.filter(y => y.id != json.data.id) | ||
|
||
message.channel.send(`the game ${json.data.names.international} got successfully deleted`); | ||
} | ||
await fs.promises.writeFile('./storage.json', JSON.stringify(storageObject)); | ||
const ares = await fetch(`https://www.speedrun.com/api/v1/games?name=${x}`); | ||
let ajson = await ares.json(); | ||
if (!ajson.data) { | ||
message.reply(errormsg) | ||
continue; | ||
} | ||
if (ajson.data[0]) { | ||
json.data = ajson.data.find(y => y.names.international == x.replace('%20', ' ')); | ||
if (!json.data) { | ||
message.reply(errormsg); | ||
continue; | ||
} | ||
} else { | ||
json = ajson; | ||
} | ||
} | ||
const game = await Game.findOne({ | ||
where: { | ||
id: json.data.id | ||
} | ||
}); | ||
|
||
} | ||
if (!game) { | ||
message.reply('i can\'t delete a game that never got added'); | ||
continue; | ||
} | ||
const isGameInGuild = guild.hasGame(game); | ||
if (!isGameInGuild) { | ||
message.reply('i can\'t delete a game thats not in the list'); | ||
continue; | ||
} | ||
games.push(game) | ||
message.channel.send(`the game ${json.data.names.international} got successfully deleted`); | ||
} | ||
await guild.removeGames(games); | ||
} | ||
}; |
Oops, something went wrong.