What it is: Pobbot is a Discord bot that monitors base health (from https://discoverygc.com/forums/bases.php) and determines if the base is repairing, degrading, low health or under attack. It sends alerts to the configured channel.
How to set up:
1. Add the bot to your Discord server by using this link: https://discordapp.com/api/oauth2/author...&scope=bot
The bot needs Send Message and Mention Everyone permissions. Manage Messages permission optional but reccommended.
2.Decide which channel on your server you want Pobbot to communicate on, make sure that it has access to this channel.
In the channel send the command !addpobbot
(You can remove Pobbot from a channel by using !rempobbot)
3. Now you need to add some bases to monitor.
You can add bases individually by using !addbase <basename>
You can add multiple bases by using !addbase <basename>,<basename>,<basename> etc.
(You can remove bases by using !rembase <basename>)
4. Optionally, you can set the level of your alerts, for example you might only want to know if it's under attack or Low health. By default All alerts are switched on. The command for this is:
!level <attack/low/degrade/all/off>
attack - Alerts when an attack is detected only
low - The above + Will alert when the base health is less than 10% and not repairing or under attack
degrade - The above + Will alert when the base health starts declining due to wear and tear
All - All of the above, plus alerts when a base starts repairing
Off - no alerts
Supported commands:
!addpobbot - tells the bot to use the channel
!rempobbot - tells the bot to stop using the channel
!add base name,name,name etc. - adds the bases you want to be monitored
!rem base name - removes the selected base
!baseloc name,system -tells pobbot where a base is, if it gets attacked it tells you who was in the system
!poblevel attack/low/degrade/all/off - What level of alerting you want (see 4. above)
!mention here/everyone/UserID/&RoleID - When an attack/low health alert is sent who you want it to mention
!base - Shows a report of all the bases you are monitoring
!config - returns the configuration applied to the channel
!help - list of available commands
PIRBOT:
This module has been added to Pobbot. Pirbot scans the player list, categorises players and can send alerts if you set thresholds. If you are going to use it I’d suggest putting it in it’s own channel just to be neater, but it isn't a requirement. Pirbot sends a message for each category, and then edits these messages instead of sending new ones. If you don’t want to use this, just don’t use any of the commands below.
!add enemies tag/name
- Adds players to your enemies category. These will be displayed in your enemies category if they are in your ZoI.
!add regions/systems name
- Set up a ZoI, then your enemies will only show/alert if within this. If not defined, then your ZoI is sirius-wide.
!add restricted name
- Add a restricted zone (for example Alaska, Thuringia etc.) It will display players/alert if players are here. Players which are in your “Friends” category will not be included.
!add friends tag/name
- Friends will show in your Friends category if online (I may add a ZoI option for this), they won’t be included in the Restricted Zone category.
!add faction tag/name
- If you set this and have set alert thresholds they will only alert if a player with this tag/name are online
With all add commands you can add multiple items at a time by using commas. Example:
!add enemies LN,LSF,LPI
!rem base/enemies/regions/systems/restricted/friends/faction tag/name
- You can only remove one item at a time. If you really mess up !rempobbot will remove your channel's configuration so that you can start again.
!pirlevel on/off
- Enables/Disables the display of the Friends category
- Default = on
!enemynumber number
- An alert is sent if number of enemies >= this number
- Default = 0 (off)
!restrictnumber number
- An alert is sent if the number of players in restricted zone >= this number
- Default = 0 (off)
!leavelog on/off
-Send a message when somebody leaves your restricted area (so that you can track who has been there).
- Default = off
!active
-Tells you the most active zones in Sirius, if you have defined a ZoI, it will tell you what players are in this ZoI
!bump
Removes the existing messages for the three categories, and sends new messages for them which are then updated. Useful if people chat in this channel so that you don't have to scroll up.
Other commands: !wiki item Returns a link for the discovery wiki site with your search item. !ai message - just a bit of fun really, send it a message and see how it responds. This is managed by a Rheinlander so may be a bit biased.
Can I run it myself or modify it?
This bot is open source: https://github.com/dr-lameos/Pobbot Note: this is my first javascript project, and first Discord bot, so I'm aware it's not as neat and pretty as it could be - be nice.
Known Limitations:
This bot relies on the forum page (https://discoverygc.com/forums/bases.php) working. If it stops updating or isn't accessible the bot will also not work. When the page starts working again you may get some false alerts
This bot scans the forum page every 15 minutes 10 seconds - so there may be a delay in receiving notification of attack.
This bot detects if a base is Under Attack if the health reduces by more than 0.005% between scans.
This bot may restart overnight with Server updates - when this happens it takes two scans for the bot to know if health is going up or down. During this period you may have limited data, or it might send a reminder of degrading bases/low health bases.
Some bases have got spaces after their names, for example 'Medway Dock '. They can still be added by doing:
!addbase Medway Dock ,
This will also add an empty base, so then do this to get rid of it:
!rembase
It is in beta - there probably are bugs.
Price:
This bot is free, but if you'd like to donate you can send credits to:
Lameos.Bank1
If you're feeling especially generous you can send bitcoin to:
16FppmC7Kbs3BQm3ePVyYErfi8nB8yAJLw (other crypto is also gratefully accepted - PM me if you want)
Okay, this is going to be a big post. Hope you like feedback. I'll preface this with saying that this analysis is from a skim read of your project, and is my no means an in-depth review. (Judging by your code, I'd say with a degree of certainty, you were following this tutorial)
Key notes:
- You have a single js file that's almost 600 lines and is running in a err... linear fashion. Consider moving your events to their own files and then having a single startup file. Use module.exports or export default function for the events and then move the other functions to an independent file.
- You are requiring fs every time you use it. This is a bad practice.
- You are importing winston for logging, which isn't a bad idea, but you declare it, use it once, then revert to using console.log and console.error throughout the rest of your code.
- You have fs listed in your package.json - don't do this. It's been part of Node since 8.0 iirc.
- You are storing everything inside of json files and writing to them constantly. This is a terrible idea, and there are numerious articles on the internet on why you shouldn't use json for persistence (config files are fine, obviously).
- We are living in 2019 but your code is acting like it's 2012. Use modern syntax. E.g. replace var with let/const, use arrow functions, etc.
- You are using extremely nested if functions, inside of loops. Use break, continue, and return statements for better control.
- You are chaining a lot of "if {} else if {} else if {} else if {}" etc. I would suggest using switch case statements instead.
- You have unused variables declared throughout your code.
- You are sending messages to Discord using a deprecated method (sendMessage had support removed like two versions ago). Use msg.channel.send instead.
- Your code is seriously lacking formatting in many places. Malformed indents (sometimes spaces are used), missing indents at times, random line breaks throughout your code, etc.
- Your message event function is an absolute disaster. With all due respect, you need to seriously rework that. Using a switch and case as a command handler is a pretty daft way of command checking; look into using module.exports/export default function. In addition you are nested function declarations, which is one of the most dated JS practices I've ever seen. Don't do that unless you really have to. Your message event is pulling in unneeded params, you only need the msg object.
- From what I can tell you are hardlocking the prefix to ! which is a very common prefix by other bots and will cause a lot of issues in other servers. If you use a common prefix, make a command to change it.
- Loading the base page you are doing an "if (err) throw err;". If the forums went down for even a second, this would crash your bot. Use proper error handling.
- COMMENT YOUR CODE. When it's got so many formatting issues, it's very difficult to analyse.
- Reading this (and I could be wrong with this assumption), I am under the impression you have copied and pasted a lot of different snippets from various places.
- The end of your message event has a duplicate switch case that is testing against true. I can't even... what?
I would really suggest looking into async/await rather than simply relying on your setTimeout. Using setTimeout over and over (especially with your get requests and extremely long loops) can cause a lot of undesired behaviour and exceptions to be thrown. You are effectively going "yeah, this function will probably take about... err five seconds? I guess?".
(04-16-2019, 04:37 PM)dr lameos Wrote: Price:
This bot is free, but if you'd like to donate you can send credits to:
Lameos.Bank1
If you're feeling especially generous you can send bitcoin to:
16FppmC7Kbs3BQm3ePVyYErfi8nB8yAJLw (other crypto is also gratefully accepted - PM me if you want)
I'll end off by saying I personally find it extremely out of taste to request donations for a community project. I, like many of the others before me, have invested hundreds of hours into the development of this game and utilities for it and have never asked a penny for it. If this project took you months, it'd be a little more understandable, but something this small that is so evidently from an amateur just rubs me the wrong way.
I hope my notes are helpful to you, and if you have questions post here or message me over Discord. As many of the community know, I am always eager to help others learn code.
Posts: 2,077
Threads: 112
Joined: Nov 2018
Staff roles: Server Administrator
(04-16-2019, 08:57 PM)Swallow Wrote: Even if it rubs you the wrong way, Laz, you could have mentioned it in PM. I find it a bit inappropriate for you to mention it here.
I do not see how this is inappropriate, as he is giving him some good feedback to help him out. I know I wouldn't mind seeing where I can improve on.
Nice job dr lameos I will have a look at it and see how she goes.
Edit: just tried it and it seems to be working fine @dr lameos
if i was into coding i would expect the same kind of reply that Laz has mentioned, same as when i do my gfx work, if someone finds a mistake or has constructive reply i would learn from it
my question
im in 2 different discords, could this bot work to just show me when im in the other one not the disco one?
(04-17-2019, 05:32 AM)kerfy Wrote: It tells me that my POB does not exist
It needs to have the exact same name as on the POB status page, and is case sensitive
(04-17-2019, 09:30 AM)evanz Wrote: im in 2 different discords, could this bot work to just show me when im in the other one not the disco one?
Not sure I understand fully - Your Pobbot configuration is specific to the server channel you select. So add Pobbot the the server/channel you want alerts on, and don't add it to the one you don't want alerts on?
(04-16-2019, 08:36 PM)Laz Wrote: Okay, this is going to be a big post. Hope you like feedback. I'll preface this with saying that this analysis is from a skim read of your project, and is my no means an in-depth review. (Judging by your code, I'd say with a degree of certainty, you were following this tutorial)
Quote:Key notes:
You have a single js file that's almost 600 lines and is running in a err... linear fashion. Consider moving your events to their own files and then having a single startup file. Use module.exports or export default function for the events and then move the other functions to an independent file.
- You are requiring fs every time you use it. This is a bad practice.
I think what I generally haven’t worked out yet is how to pass variables to a function - leading to them being nested, repeated or using global vars
Quote:- You are importing winston for logging, which isn't a bad idea, but you declare it, use it once, then revert to using console.log and console.error throughout the rest of your code.
- You have fs listed in your package.json - don't do this. It's been part of Node since 8.0 iirc.
I’ll correct this.
Quote:- You are storing everything inside of json files and writing to them constantly. This is a terrible idea, and there are numerious articles on the internet on why you shouldn't use json for persistence (config files are fine, obviously).
In effect my json is a configuration file - originally it was static - then I made it editable through commands. It could be moved to a database, but seems a bit unnecessary at this point.
Quote:- We are living in 2019 but your code is acting like it's 2012. Use modern syntax. E.g. replace var with let/const, use arrow functions, etc.
That makes sense, last time I was involved in any code it was 2011!
Quote:- You are using extremely nested if functions, inside of loops. Use break, continue, and return statements for better control.
- You are chaining a lot of "if {} else if {} else if {} else if {}" etc. I would suggest using switch case statements instead.
I know, it could be a lot cleaner. It's gone through 5 large revisions so far and I'm intending to do more. However I've decided to release it at this point, as it's working and has the necessary functionality
Quote:- You have unused variables declared throughout your code.
Can you give an example? I can only see the one (page)
Quote:- You are sending messages to Discord using a deprecated method (sendMessage had support removed like two versions ago). Use msg.channel.send instead.
Thanks, I'll blame that on the tutorial
Quote:- Your code is seriously lacking formatting in many places. Malformed indents (sometimes spaces are used), missing indents at times, random line breaks throughout your code, etc.
I put it through a beautifier, maybe I made some changes after that
Quote:- Your message event function is an absolute disaster. With all due respect, you need to seriously rework that. Using a switch and case as a command handler is a pretty daft way of command checking; look into using module.exports/export default function.
Bit harsh, could you explain a bit more what the problem is here?
Quote:In addition you are nested function declarations, which is one of the most dated JS practices I've ever seen. Don't do that unless you really have to. Your message event is pulling in unneeded params, you only need the msg object.
Yes I need to figure out how to pass variables to functions]
Quote:- From what I can tell you are hardlocking the prefix to ! which is a very common prefix by other bots and will cause a lot of issues in other servers. If you use a common prefix, make a command to change it.
Yes it's using ! - I'll review this, the servers I'm on don't have many bots
Quote:- Loading the base page you are doing an "if (err) throw err;". If the forums went down for even a second, this would crash your bot. Use proper error handling.
- COMMENT YOUR CODE. When it's got so many formatting issues, it's very difficult to analyse.
Both noted
Quote:- Reading this (and I could be wrong with this assumption), I am under the impression you have copied and pasted a lot of different snippets from various places.
Kind of, The discord bits have largely been copied/pasted and I have generally used a lot of snippets from various tutorials and stack overflow etc.
However the baseLoad, healthCompare and baseAlert functions, are my own.
Quote:- The end of your message event has a duplicate switch case that is testing against true. I can't even... what?
Well spotted
Quote:I would really suggest looking into async/await rather than simply relying on your setTimeout. Using setTimeout over and over (especially with your get requests and extremely long loops) can cause a lot of undesired behaviour and exceptions to be thrown. You are effectively going "yeah, this function will probably take about... err five seconds? I guess?".
async/await is something I have just started looking at and haven't gotten my head around yet.
A few of the timeouts are necessary in order to put longer messages in the right order on Discord
Quote:I'll end off by saying I personally find it extremely out of taste to request donations for a community project. I, like many of the others before me, have invested hundreds of hours into the development of this game and utilities for it and have never asked a penny for it. If this project took you months, it'd be a little more understandable, but something this small that is so evidently from an amateur just rubs me the wrong way.
I thought I would get a gripe on this and considered not including it. This project is a learning project for me, I'm not looking to make anything from the community for it. I've open sourced it so that I can have useful feedback, and so that if somebody else wants to use it in their projects or host it themselves they can.
However because some people that have had access to the earlier versions have said they would like to give something for it I decided to include the options. I'm not requesting a donation, go use it for free I don't mind, but if somebody wants to they can.
I've also seen a lot of developers quit over the years, including you Laz, because they've built all of these tools and content and don't feel appreciated or rewarded. Some community members have a mindset that developers/game masters/moderators are their servants and owe them something. Perhaps if we supported them instead of expecting them to provide everything to us then there'd be a happier developer base and more contribution. People happily pay for signatures/logos and even commodity deliveries, why not development?