-
Notifications
You must be signed in to change notification settings - Fork 0
New Features, Optimizations, and Code Style Improvements #14
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
Draft
ihasTaco
wants to merge
5
commits into
main
Choose a base branch
from
develop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2021": true | ||
}, | ||
"extends": "google", | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"rules": { | ||
"max-len": "off", | ||
"linebreak-style": "off" | ||
} | ||
} |
This file contains hidden or 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,47 +1,102 @@ | ||
const axios = require('axios'); | ||
require('dotenv').config({ path: './.env' }); | ||
const logger = require('../utils/logger'); | ||
require('dotenv').config({path: './.env'}); | ||
|
||
async function getGuilds(page = 0, pageSize = 10) { | ||
const guilds = await axios.get(`${process.env.BACKEND_URL}api/get/bot/guilds`, { | ||
params: { | ||
page: page, | ||
pageSize: pageSize | ||
} | ||
}); | ||
return guilds; | ||
/** | ||
* | ||
* @return {object} | ||
*/ | ||
async function getGuilds() { | ||
logger.debug(`Fetching guilds`); | ||
const guilds = await axios.get(`${process.env.BACKEND_URL}api/get/bot/guilds`); | ||
return guilds.data; | ||
} | ||
|
||
async function getServerUUIDsForGuild(guild_id) { | ||
const servers = await axios.get(`${process.env.BACKEND_URL}api/get/bot/${guild_id}/servers`, {}); | ||
return servers; | ||
/** | ||
* | ||
* @param {string} guildID | ||
* @return {object} | ||
*/ | ||
async function getServerUUIDsForGuild(guildID) { | ||
logger.debug(`Fetching server UUIDs for guild: ${guildID}`); | ||
const servers = await axios.get(`${process.env.BACKEND_URL}api/get/bot/${guildID}/servers`, {}); | ||
return servers; | ||
} | ||
|
||
async function getServerDetails(guild_id, server_uuid) { | ||
const details = await axios.get(`${process.env.BACKEND_URL}api/get/bot/${guild_id}/server/${server_uuid}`, {}); | ||
return details; | ||
/** | ||
* | ||
* @param {string} guildID | ||
* @param {string} serverUUID | ||
* @return {object} | ||
*/ | ||
async function getServerSettings(guildID, serverUUID) { | ||
logger.debug(`Fetching server details for guild: ${guildID} and server UUID: ${serverUUID}`); | ||
const settings = await axios.get(`${process.env.BACKEND_URL}api/get/bot/${guildID}/server/${serverUUID}`, {}); | ||
return settings.data; | ||
} | ||
|
||
async function getServerInfo(guild_id, server_uuid) { | ||
const serverInfo = await axios.get(`${process.env.BACKEND_URL}api/get/bot/${guild_id}/serverInfo/${server_uuid}`, {}); | ||
return serverInfo; | ||
/** | ||
* | ||
* @param {string} guildID | ||
* @param {string} serverUUID | ||
* @return {object} | ||
*/ | ||
async function getServerInfo(guildID, serverUUID) { | ||
logger.debug(`Fetching server info for guild: ${guildID} and server UUID: ${serverUUID}`); | ||
let serverInfo; | ||
try { | ||
serverInfo = await axios.get(`${process.env.BACKEND_URL}api/get/bot/${guildID}/serverInfo/${serverUUID}`, {}); | ||
} catch { | ||
logger.warn(`Couldn't find info for guild: ${guildID} and server UUID: ${serverUUID}`); | ||
logger.info(`Creating new info for guild: ${guildID} and server UUID: ${serverUUID}`); | ||
serverInfo = {'players': 0, 'ping': 0, 'map': null, 'status': null, 'last_restart': null, 'message_id': null}; | ||
writeServerInfo(guildID, serverUUID, serverInfo); | ||
} | ||
return serverInfo; | ||
} | ||
|
||
async function writeServerInfo(guild_id, server_uuid, server_info) { | ||
try { | ||
const response = await axios.post(`${process.env.BACKEND_URL}api/post/write-server-info`, { | ||
guild_id, | ||
server_uuid, | ||
server_info, | ||
}); | ||
} catch (error) { | ||
console.error('Error: ', error); | ||
} | ||
/** | ||
* | ||
* @param {string} guildID | ||
* @param {string} serverUUID | ||
* @param {object} queryState | ||
*/ | ||
async function writeServerInfo(guildID, serverUUID, queryState) { | ||
try { | ||
logger.debug(`Writing server info for guild: ${guildID} and server UUID: ${serverUUID}`); | ||
await axios.post(`${process.env.BACKEND_URL}api/post/write-server-info`, { | ||
guildID, | ||
serverUUID, | ||
queryState, | ||
}); | ||
} catch (error) { | ||
logger.error(`Error writing server info for guild: ${guildID} and server UUID: ${serverUUID}, error: ${error}`); | ||
} | ||
} | ||
/** | ||
* | ||
* @param {string} guildID | ||
* @param {string} serverUUID | ||
* @param {object} messageID | ||
*/ | ||
async function writeMessageID(guildID, serverUUID, messageID) { | ||
try { | ||
logger.debug(`Writing server info for guild: ${guildID} and server UUID: ${serverUUID}`); | ||
await axios.post(`${process.env.BACKEND_URL}api/post/write-message-id`, { | ||
guildID, | ||
serverUUID, | ||
messageID, | ||
}); | ||
} catch (error) { | ||
logger.error(`Error writing server info for guild: ${guildID} and server UUID: ${serverUUID}, error: ${error}`); | ||
} | ||
} | ||
|
||
module.exports = { | ||
getGuilds, | ||
getServerUUIDsForGuild, | ||
getServerDetails, | ||
getServerInfo, | ||
writeServerInfo | ||
}; | ||
getGuilds, | ||
getServerUUIDsForGuild, | ||
getServerSettings, | ||
getServerInfo, | ||
writeServerInfo, | ||
writeMessageID, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Server crash