Skip to content

Commit

Permalink
Fixing stuff (#38)
Browse files Browse the repository at this point in the history
* bug fixes and new feature month_name and nomnth_number variables

* small fixes

* Update nodejs.yml

* minor updates

* user limit fixed and made faster

* improvements
  • Loading branch information
keybraker authored Nov 29, 2020
1 parent 80dca36 commit 90aaeb4
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 178 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ on:
jobs:
pass_code_from_linter:
runs-on: ubuntu-latest

steps:
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
Expand Down
2 changes: 1 addition & 1 deletion assets/classes/portal_class.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module.exports = class {
this.creator_id = creator_id;
this.regex_portal = regex_portal;
this.regex_voice = regex_voice;
this.voice_list = voice_list;
this.no_bots = no_bots;
this.limit_portal = limit_portal;
this.time_to_live = time_to_live;
this.refresh_rate = refresh_rate;
this.locale = locale;
this.voice_list = voice_list;

this.ann_announce = ann_announce;
this.ann_user = ann_user;
Expand Down
18 changes: 1 addition & 17 deletions assets/jsons/game_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"status": "Apex Legends",
"type": "game",
"locale": {
"en": "Apex Legends",
"en": "Apex",
"gr": "Κορυφαίοι Θρύλοι"
}
},
Expand Down Expand Up @@ -56,22 +56,6 @@
"gr": "Μην Πεθάνετε Μαζί"
}
},
{
"status": "Apex Legends",
"type": "game",
"locale": {
"en": "Apex Legends",
"gr": "Κορυφαίοι Θρύλοι"
}
},
{
"status": "Apex Legends",
"type": "game",
"locale": {
"en": "Apex Legends",
"gr": "Κορυφαίοι Θρύλοι"
}
},
{
"status": "Overwatch",
"type": "game",
Expand Down
4 changes: 2 additions & 2 deletions assets/jsons/program_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"status": "Spotify",
"type": "music",
"locale": {
"en": "Spotify",
"gr": "Μουσική"
"en": "",
"gr": ""
}
},
{
Expand Down
2 changes: 0 additions & 2 deletions commands/corona.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const get_country_code = function(country) {
return country_codes[i].name;
}
}

return null;
};

Expand Down Expand Up @@ -58,7 +57,6 @@ module.exports = async (client, message, args, portal_guilds, portal_managed_gui
},
};


http_mngr(options)
.then(rspns => {
const json = help_mngr.getJSON(rspns.toString().substring(rspns.toString().indexOf('{')));
Expand Down
6 changes: 4 additions & 2 deletions commands/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const compare = function(member_a, member_b) {
module.exports = async (client, message, args, portal_guilds, portal_managed_guilds_path) => {
return new Promise((resolve) => {
member_list = portal_guilds[message.guild.id].member_list;
let length = args.length > 0 ? +args[0] : Object.keys(member_list).length;
let length = (+args.length > 0 && Object.keys(member_list).length >= args.length)
? +args[0]
: 9;

if(!isNaN(length)) {
if (portal_guilds[message.guild.id].member_list) {
Expand All @@ -23,7 +25,7 @@ module.exports = async (client, message, args, portal_guilds, portal_managed_gui
if (this_member !== null && this_member !== undefined && length > 0) {
member_levels.push(
{
emote: `${i}. ${this_member.displayName}`,
emote: `${i+1}. ${this_member.displayName}`,
role: `points: ${Math.round(member_list[member_id].points)}`,
inline: false,
},
Expand Down
123 changes: 123 additions & 0 deletions commands/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/* eslint-disable no-unused-vars */
const country_codes = require('../assets/jsons/country_codes.json');

const http_mngr = require('../functions/http_requests');
const help_mngr = require('../functions/help_manager');

const moment = require('moment');
const voca = require('voca');

const get_country_code = function(country) {
for (let i = 0; i < country_codes.length; i++) {
if (voca.lowerCase(country_codes[i].name) === voca.lowerCase(country)) {
return country_codes[i].name;
}
else if (voca.lowerCase(country_codes[i].code) === voca.lowerCase(country)) {
return country_codes[i].name;
}
}
return null;
};

module.exports = async (client, message, args, portal_guilds, portal_managed_guilds_path, user_match) => {
return new Promise((resolve) => {
let code = null;

if (args.length === 1) {
code = get_country_code(args[0]);
if (code === null) {
return resolve ({
result: false,
value: `*${args[0]} is neither a country name nor a country code.*`,
});
}
}
else if(args.length > 1) {
return resolve ({
result: false,
value: '*you can run "./help corona" for help.*',
});
}
else {
return resolve ({
result: false,
value: '*Global stats are temporarily unavailable.*',
});
}

const options = {
'method': 'GET',
'hostname': 'http://newsapi.org',
'port': null,
'path': '/v2/everything',
'headers': {
'q': 'bitcoin',
'orgfrom': '2020-09-19',
'sortBy': 'publishedAt',
'apiKey': 'publishedAt',
},
};

http_mngr(options)
.then(rspns => {
const json = help_mngr.getJSON(rspns.toString().substring(rspns.toString().indexOf('{')));
if(json === null) {
return resolve ({
result: false,
value: 'data from source was corrupted',
});
}

if (json.errors.length === 0) {
const country_data = json.response.find(data => data.country === code);

message.channel.send(
help_mngr.create_rich_embed(`COVID19 ${country_data.country} stats ${moment().format('DD/MM/YY')}`,
'covid-19 be api-sports', '#FF0000', [
{
emote: 'NEW cases',
role: `***${country_data.cases.new}***`, inline: true },
{
emote: 'NEW deaths',
role: `***${country_data.deaths.new}***`, inline: true },
{
emote: 'Tests P1M',
role: `***${country_data.tests['1M_pop']}***`, inline: true },
{
emote: 'Cases',
role: `***${country_data.cases.total}***`, inline: true },
{
emote: 'Deaths',
role: `***${country_data.deaths.total}***`, inline: true },
{
emote: 'Recovered',
role: `***${country_data.cases.recovered}***`, inline: true },
{
emote: '%Recovered',
role: `***${((country_data.cases.recovered / country_data.cases.total) * 100)
.toFixed(2)}%***`, inline: true },
{
emote: '%Diseased',
role: `***${((country_data.deaths.total / country_data.cases.total) * 100)
.toFixed(2)}%***`, inline: true },
{
emote: 'Critical',
role: `***${country_data.cases.critical}***`, inline: true },
], null, null, true));
return resolve({ result: true, value: `*${country_data.country} corona stats.*` });
}
else {
return resolve({
result: false,
value: `*${args[0]} is neither a country name nor a country code.*`,
});
}
})
.catch(rspns => {
return resolve({
result: false,
value: '*Could not access the server*',
});
});
});
};
12 changes: 6 additions & 6 deletions commands/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const guld_mngr = require('../functions/guild_manager');
module.exports = async (client, message, args, portal_guilds, portal_managed_guilds_path) => {
return new Promise((resolve) => {
message.guild.channels
.create('general', { type: 'category' })
.create('portal-hub', { type: 'category' })
.then(cat_channel => {
message.guild.channels.cache.forEach(channel => {
if(channel.id === portal_guilds[message.guild.id].spotify ||
Expand All @@ -17,16 +17,16 @@ module.exports = async (client, message, args, portal_guilds, portal_managed_gui
});

guld_mngr.create_portal_channel(
message.guild, 'general-portal', cat_channel, portal_guilds[message.guild.id].portal_list,
message.guild, 'portal-to-voice', cat_channel, portal_guilds[message.guild.id].portal_list,
portal_guilds, message.member.id);
guld_mngr.create_spotify_channel(
message.guild, 'general', cat_channel, portal_guilds[message.guild.id]);
message.guild, 'spotify', cat_channel, portal_guilds[message.guild.id]);
guld_mngr.create_announcement_channel(
message.guild, 'general', cat_channel, portal_guilds[message.guild.id]);
message.guild, 'announcement', cat_channel, portal_guilds[message.guild.id]);
guld_mngr.create_url_channel(
message.guild, 'general', cat_channel, portal_guilds[message.guild.id].url_list);
message.guild, 'url-only', cat_channel, portal_guilds[message.guild.id].url_list);
guld_mngr.create_music_channel(
message.guild, 'general', cat_channel, portal_guilds[message.guild.id]);
message.guild, 'music-player', cat_channel, portal_guilds[message.guild.id]);
})
.catch(console.error);

Expand Down
38 changes: 30 additions & 8 deletions events/messageReactionAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,40 +112,62 @@ const reaction_music_manager = function(args) {
break;
}
case '⏹' : {
if(current_guild.dispatcher !== null && current_guild.dispatcher !== undefined) {
return_value.value = 'player is not connected';
break;
}
if(!current_guild.music_data.votes.includes(args.user.id)) {
current_guild.music_data.votes.push(args.user.id);
}

const votes = current_guild.music_data.votes.length;
const users = voice_connection_in_reaction_guild.channel.members.filter(member => !member.user.bot).size;
const users = voice_connection_in_reaction_guild.channel.members
.filter(member => !member.user.bot).size;

if (votes >= users / 2 || args.user.presence.member.hasPermission('ADMINISTRATOR')) {
return_value.value = 'stoping player';
if (votes >= users / 2) {
return_value.value = 'stopping player (majority)';
musc_mngr.stop(args.messageReaction.message.guild.id, args.guild_list,
args.messageReaction.message.guild);
current_guild.music_data.votes = [];
}
else if (args.user.presence.member.hasPermission('ADMINISTRATOR')) {
return_value.value = 'stopping player (admin)';
musc_mngr.stop(args.messageReaction.message.guild.id, args.guild_list,
args.messageReaction.message.guild);
current_guild.music_data.votes = [];
}
else {
return_value.value = `${votes}/${users / 2} (majority needed to stop/admins)`;
return_value.value = `${votes}/${users / 2} (majority or admin authorization needed to stop)`;
}
break;
}
case '⏭' : {
if(current_guild.dispatcher !== null && current_guild.dispatcher !== undefined) {
return_value.value = 'player is not connected';
break;
}
if(!current_guild.music_data.votes.includes(args.user.id)) {
current_guild.music_data.votes.push(args.user.id);
}

const votes = current_guild.music_data.votes.length;
const users = voice_connection_in_reaction_guild.channel.members.filter(member => !member.user.bot).size;
const users = voice_connection_in_reaction_guild.channel.members
.filter(member => !member.user.bot).size;

if (votes >= users / 2 || args.user.presence.member.hasPermission('ADMINISTRATOR')) {
return_value.value = 'skipping video';
if (votes >= users / 2) {
return_value.value = 'skipping video (majority)';
musc_mngr.skip(args.messageReaction.message.guild.id, args.guild_list,
args.client, args.messageReaction.message.guild);
current_guild.music_data.votes = [];
}
else if (args.user.presence.member.hasPermission('ADMINISTRATOR')) {
return_value.value = 'skipping video (admin)';
musc_mngr.skip(args.messageReaction.message.guild.id, args.guild_list,
args.client, args.messageReaction.message.guild);
current_guild.music_data.votes = [];
}
else {
return_value.value = `${votes}/${users / 2} (majority needed to skip/admins)`;
return_value.value = `${votes}/${users / 2} (majority or admin authorization needed to skip)`;
}
break;
}
Expand Down
Loading

0 comments on commit 90aaeb4

Please sign in to comment.