Giter Site home page Giter Site logo

dignityofwar / digbot Goto Github PK

View Code? Open in Web Editor NEW
13.0 13.0 1.0 2.07 MB

DigBot is a custom made Discord bot for the DIG gaming community

Home Page: https://dignityofwar.com

License: MIT License

Dockerfile 0.54% Shell 0.13% Go 99.33%
bot discord discord-bot docker games planetside

digbot's People

Contributors

github-actions[bot] avatar jameslongman avatar microwavekonijn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

maelstromeous

digbot's Issues

Legacy Issue: Add a timeout for the !Staff and !Developers PM commands

Possible exploit here, now the code is going public I'm going to do us all a favor and bump this to high priority.

Original issue by Maelstromeous:

Just realised that we don't have any kind of anti spam for the direct message commands. We could have DIGBot spam is all day and we'd have to mute it.

Recommend we add a logarithmic time out, where they can send us messages say twice and then if they keep sending the messages they will have to be prevented for a time. If they send us messages after the timeout it keeps increasing the timeout until they stop and get bored.

!dragons command does not always receive a response

Upon typing !dragons in the bot command channel DIGBot should let the user know that it has either added or removed their dragons role, this message is not always sent. This may also affect the adding and removal of the tag.

Update repository

This repository was not the original home of DIGBot's code. The previous repository was private so things like the readme need to be updated with public viewing in mind.

Current issues that we wish to keep also need to be moved over.

Those who have previously contributed to the project should have their work acknowledged on the GitHub repo's landing page as the commit history has been wiped.

Deploy DIGBot to production

Relies on #3

We will need to deploy the master branch of this repository to live, in previous production deployments we usually had a couple of devs with a few hours free in-case hotfixing was required

Legacy Issue: Change pruning to run off database

I just want to put out there that I was and still am scared of this feature. Any attempt at implementation will require extreme tests, safeguards, and rigorous QA. Mess this up and you could nuke a server, like a full blown Thanos snap

Original issue by James:

Currently we're using discord built in pruning feature, unfortunately this doesn't tell us who we're kicking only how many. Also we're limited to the choice of 1, 7, or 30 days when we would prefer 90.

Setup so the database knows the last time each member was active and run pruning based off that instead. Be veeeeeeeeeeeery careful with this functionality, probably best to be very strict code wise with the conditions for kicks and also require a staff member to manually sign off on daily kicks greater than 10 (something like !admin prune force)

Update to discord.js 11.4.2

I looked at an update for the discord.js dependency and it should be possible without the need to change of any code. There are a lot of fixes and only a few things we should be aware of, which I listed:

11.0.0 > 11.1.0

  • <channel>.sendMessage and <channel>.sendFile deprecated, replaced by <channel>.send (old methods forward to new method)
  • Sending typing states less frequent #9

> 11.2.0

  • <guild>.defaultChannel deprecated (not removed yet, stated that it will be removed in version 12)

> 11.3.0 > 11.3.1 > 11.3.2

  • none

>11.4.0

  • <collection>.find changed to accept function as argument (still allows the old arguments, but will be removed(already done in the dev version))
  • All user bot methods deprecated(?, doesn’t seem to affect the bot)

> 11.4.1 > 11.4.2

  • none

Legacy Issue: Refactor Hardcoded event schedule to allow hourly resolution by date

Original issue by Maelstromeous:

Currently, we're restricted to a single start hour EVERY day. Ideally, we need the ability to provide a start hour on a by day basis.

Below shows 0 indexed days (0 being Sunday in Javascript ¯_(ツ)_/¯ ), providing 24hr start times. In this example, we have an event on Wednesday, starting at 19:00 and ends at 22:00. Again, another event on Saturday, starting at 18:00 and ends at 21:00.

{
    event: {
        days: [
            2 => {
                start: 19,
                end: 22
            },
            5 => {
                start: 18,
                end: 21
            }
        ]
    }
}

Legacy issue: Expand detectplaying.js tests

Original issue by James:

admin/roles/detectplaying.js could actually probably be tested working in action to protect the module in the future. It will require server.js and config.js manipulation to prevent messages firing and building of mapped collections within probably both the member and config objects. I can see why I skipped doing it when I did the admin tests but it's definitely somewhere we can improve if we have spare time

MCS currently disabled

Modular Channel System: Adaptively create new voice channels as others become full, deletes them when no longer in use.

MCS system is currently disabled, it was probably broken in the subchannel discord update. Someone will need to communicate with the community staff if they want this feature re-implimented, and depending on their answer either remove it from the project files or update it to work in line with the new subchannel system.

A quick fore-warning: MCS code is some of the most complex code in the project

Legacy Issue: Build automated system to log training attendance

James:
We can automate the registering of trainings which would benefit not just DIG but also DIGT if they're still doing their core trainings.

Ideas:
"!training start" to start a training in your voice channel

The bot will then prompt you for a training topic which you can pick from a list of trainings you're authorised to give, core 1, core 2, for DIGT. Bio labs, tech plants, scythes, sundies for DIG etc. Or you could pick general if it's not on the list.

At the end of the training you then type "!training end" the bot will then count all the people that have been there the whole time and record them in the database, it could also pm them to let them know they've been successfully registered.

To take the feature further before training starts you could type !training suggest and the bot would tell you the trainings that most people in the channel don't have. Currently blocked by database integration, also kind of by members section, but once the database it up the discord end of the feature should certainly be able to be fully completed

Refactor how "\\" is handled in sub-bots.js

Currently, every single time a token or id is used in sub-bots.js, the string is parsed via .replace(/\/g,'') to remove the "\" that is a side effect of how it is received in Travis CI cases.

Instead of the string being passed every time it is called from the subBots object, the object should be parsed once on setup so subsequent calls do not need to use replace. It will obviously be much more efficient

Legacy Issue: Add Hitbox stream notification

Original issue by James:

Same as [referenced equivalent to #7] but with Hitbox, this might be more tricky due to the naturally less helpful API and lack of millions of open source bots that have already got it

The API itself is known to occasionally send fake messages and not send messages when it should. So build in some sort of spam protection to mitigate fake messages

API:
http://developers.hitbox.tv/

This issue requires a community API token for the bot, we never had one so one will need to be obtained. Of course please ensure this is located in envConfig.js and kept out of commit history

Get DIGBot running on staging

Rellies on #2

Once the staging server is up we can work on getting the bot hosted and running on it. At this stage we should ensure that the bot is at least as stable as the current version being run on live.

Hosting relies on Llama, once he works out how the bot is going to be hosted by the community we should be able to implement this soon as the initial master branch code will server for this purpose.

Legacy Issue: Expand upon tests for server.js by manipulating stored data

Original issue by James:

With 166 [issue requiring tests for a lot of old code] I'm adding some tests to check the module is correct and I'm also testing the non manipulated stored data to make sure the right things are being stored.

What can and probably should be done however is testing the modules true getter/setter functionality by storing fake guild/role etc objects and then fetching them back from the module to make sure they're being saved and passed back correctly.

Would of course be nice to have everything complete and perfect but this will require more effort than it's worth spending atm as QA would detect any issue with the functionality in about 5 seconds

Legacy Issue: Statistics gathering

Original issue by James:

The bot has the capacity to keep logs of what bot commands are being used and how, how many community members are playing what games, total monthly community playtime for games etc.

The ability to log so we have statistics to provide for community game activity at meetings/in our monthly reports and such would require the ability to write to a file/database. As such the feature is currently blocked until work has progressed on the website in the new year.

Rough ideas for logging:

  • Total monthly game playtime
  • Number of distinct community members per game per month
  • Number of time each bot command was called each month
  • New server members each month
  • Members pruned each month

Maelstromeous:
All this will require is a database, it's not necessarily blocked by the website.

All we'd be able to do is collect raw data, not visualise it in pretty graphs or anything.

I could quite easily get metrics tracking going, we just need to know what we're going to track. This ties in with my game tracking idea, and now we have the game detection code in that helps too.

James:
Will power DIG-website repo issue 23 [this was an issue on the old website repo about member databases], I'd like to start work on this pretty soon, I can certainly lay the foundation to collect the data pretty soon™.

The only real question is how we want to collate and derive stats from said data. The 3 possible options in my mind would be:

  1. DIGBot passes all stats as they come in to the website database, some process deals with them (bolt? sql?) at week/month intervals
  2. DIGBot tallies data node side as results come in, at hourly/daily intervals these are passed to the database to be dealt with there at week/month intervals
  3. DIGBot stores data as it comes in in a file of some sort, the data is collated node side at week/month intervals and passed to the database then for website handling

Personally I prefer option 1 as I imagine it's a bit safer with less chance of dataloss. When it comes down to what we want to actually use to do the science and order action based on it though I'm not too sure what would be best

James:
Apparently the database is working locally just not on production though so this is actually no longer blocked. Had a discussion a week or two ago about how this is going to function and Mael and I both agree option 1 is the best plan. So, within the remit of this issue:

  • Data will be collected and passed to the database as it comes in via JSON objects.

Not sure about how they're actually sending/recieving but should be able to start work tied in very closely with website repo issue 23

Maelstromeous:
It's actually going to be passed to a PHP script, not the database directly. The bot will need to send a JSON message, so this message requires a type (just a property called type which lets us control processing logic) and data points basically.

Bring over some Ava code

I actually did some work on a discord bot on my own just for fun and to improve my node skills after we wound down work on the project. Some code and features in that bot are straight upgrades of DIGBot and I plan to bring over the upgrades.

I will need to look at what code and features specifically is worth emulating so this is a very broad issue until then

This may or may not end up being a substantial refactor so I'll leave this until after stable v1 release

Legacy Issue: Build a module to handle long message strings

Original issue by James:
Currently with extremely long messages breaching the 2k character limit for discord we're either using the sendMessage method split options (which looks ugly) or failing a message when we don't have to or running a check and correction in-module.

This is an issue so common that it's deserving of its own module. Which would take a string, and either return an array of smaller strings each less than 1900 characters in length (if action is required), or if the string is <2k return the string itself.

This module should make messages look nice so the splits should be at new line (/n) notations, or if that's not possible at least at full stops.

Maelstromeous:
This would warrant it's own module. If it's made, it should be classed as a "helper" function, which ideally we should be loading via a server / config property so we have access to it throughout.

Many SFX and music assets have bad links

These could be updated but this would require volume configurations. If #18 was completed first, hopefully, we could get volume normalisation in that so it would just be a matter of replacing links.

Really these links have no business being hardcode and should be in a database anyway, handling for bad links is included in the bot so this isn't a critical issue

I believe @microwavekonijn has already got some new links ready posted into the dev channel on discord

Legacy Issue: Started typing and failsafe broken

This issue was quite complex and remained open for the majority of our previous active development, it was a low priority bug.

Original issue by Maelstromeous:

Maelstromeous:
Disabled entirely for now. Need to have it more reliably start and stop typing.

James:
This was a problem of two parts:

  1. The command to stop and start typing was being called and stopped in an inconsistent way - fixed
  2. The command to stop typing is sent but it doesn't work

I have solved the first but the second is far harder to nail down. As far as I can tell this is an API problem and there's nothing we can do. One possible solution could be to somehow wait for the stop typing command to definitely go through, and only then post the message.

Gunna leave this for someone else to take a shot at for now

Euwas:
What exactly is the issue with the start and stop typing notification? On my test server it seems to be working during a 5 minute test. Does it fail when multiple messages occur at once?

The start and stop call increase and decrease counters. Uneven calls may leave the notification active. the stop method does take an argument to force the removal of the notification though, so you can always stop it.

James:
The issue is sometimes it gets stuck on typing, repro is a bit hard as it's random but try it a few times and it'll happen. I would guess this is due to the request to stop typing being sent and it not going through, force argument didn't have an effect when I was trying to fix it, but I may have been using it wrong as I had no idea what I was doing 2 weeks ago

This may have fixed itself with discord.js 10.0.1 I'd check the force argument again

James:
Just got this again. console.log showed:
[1:15:28 AM] [WARNING] (discordbot) stopTyping timeout executed...
but it didn't stop typing, command was !ping and reply came back quickly as expected

Maelstromeous:
I wonder if it's because local commands are sent too quickly and aren't being stopped?

James:
Dunno I didn't look into it, sometimes the typing starts after the message has already been sent though. And that stopTyping timeout seems to send no matter what

Maelstromeous:
I wonder if the stop typing failsafe is failing because the msg object is no longer available to have it's stop typing message sent on? Is there a way to stop a bot from typing on a particular server?

A solution could be to build an array of channel IDs as the message comes in, and if the stop typing command has kicked in for that channel, clear it. Otherwise, send the force command.

Surely other bots have got this nailed down?

Not IDs... Full msg.channel objects... This gonna be fun.

James:
Well I still haven't taken a proper look, but at a glance I'd guess it's because you haven't used clearTimeout() to kill the failsafe if you get a good reply. Also the timeout variable is global and not function level which is asking for trouble.

I don't know how other bots have been handling it but I haven't heard bad things about this feature since v9/10. I can take another look if you can't figure it out the last time I looked at this issue was 3 months ago like 2 days after I learned JS

Legacy Issue: Couple of crashes

Original issue by James:

Little bit of instability atm had a couple of interesting crashes that need looking into:

2:29:17 AM [ERROR] (Crash Handler) [2:29:17 AM] Uncaught Exception Crash
- Last Events:
- [2:29:17 AM] (Commands Antispam) releaseUser
- [2:29:17 AM] (Commands Antispam) releaseCommand
- [2:29:17 AM] (admin.js) fiveMinCheck
- Last Messages Recieved:
- [1:01:17 AM] (Dignity of War) ?
- [1:15:56 AM] (Dignity of War) allso
- [1:15:57 AM] (Dignity of War) http://www.independent.co.uk/life-style/health-and-families/health-news/hiv-aids-vaccine-therapy-trials-no-daily-drugs-art-irsicaixa-barcelona-beatriz-mothe-a7596521.html
- TypeError: Cannot read property 'roles' of null
    at Object.module.exports.getRoles (/var/www/dignityofwar.com/bot/src/lib/server/server.js:133:33)
    at Object.module.exports.getRole (/var/www/dignityofwar.com/bot/src/lib/server/server.js:123:19)
    at Object.module.exports.release (/var/www/dignityofwar.com/bot/src/lib/admin/antispam/mentionspam.js:159:31)
    at Timeout.fiveMinCheck [as _repeat] (/var/www/dignityofwar.com/bot/src/lib/admin/admin.js:110:17)
    at Timeout.wrapper [as _onTimeout] (timers.js:417:11)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)
9:39:54 AM [ERROR] (Crash Handler) [9:39:54 AM] Uncaught Exception Crash
- Last Events:
- [9:39:31 AM] (discordbot) presenceUpdate
- [9:39:52 AM] (discordbot) presenceUpdate
- [9:39:54 AM] (!sfx) release
- Last Messages Recieved:
- [9:21:46 AM] (Dignity of War) Stop giving it weed FFS
- [9:39:01 AM] (Dignity of War) !sfx akbar
- [9:39:24 AM] (Dignity of War) !sfx admin
- TypeError: Cannot read property 'channelName' of undefined
    at VoiceConnection.connection.on (/var/www/dignityofwar.com/bot/src/commands/sfx.js:206:78)
    at emitNone (events.js:91:20)
    at VoiceConnection.emit (events.js:185:7)
    at VoiceConnection.disconnect (/var/www/dignityofwar.com/bot/node_modules/discord.js/src/client/voice/VoiceConnection.js:150:10)
    at VoiceChannel.leave (/var/www/dignityofwar.com/bot/node_modules/discord.js/src/structures/VoiceChannel.js:126:69)
    at Timeout.release (/var/www/dignityofwar.com/bot/src/commands/sfx.js:284:27)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)
10:38:12 PM [ERROR] (Crash Handler) [10:38:12 PM] Uncaught Exception Crash
- Last Events:
- [10:38:05 PM] (discordbot) message
- [10:38:05 PM] (discordbot) message
- [10:38:12 PM] (!sfx) release
- Last Messages Recieved:
- [10:37:22 PM] (Miller Server Community) https://gfycat.com/PrestigiousHiddenEasternglasslizard
- [10:37:41 PM] (Dignity of War) !sfx admin
- [10:38:05 PM] (Dignity of War) !sfx bad
- TypeError: Cannot read property 'removeAllListeners' of null
    at VoiceConnection.cleanup (/var/project/node_modules/discord.js/src/client/voice/VoiceConnection.js:314:7)
    at VoiceConnection.disconnect (/var/project/node_modules/discord.js/src/client/voice/VoiceConnection.js:299:10)
    at VoiceChannel.leave (/var/project/node_modules/discord.js/src/structures/VoiceChannel.js:126:69)
    at Timeout.release (/var/project/src/commands/sfx.js:284:27)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

Need to identify the cause of and fix all

Legacy Issue: Test failures

Original issue by James:

I've seen two different fail cases, one:

nodetest_1  |   1) sub-bots/sub-bots.js log a subBot in and out bot should have logged in correctly:
nodetest_1  |      AssertionError: expected false to be true
nodetest_1  |       at Context.<anonymous> (test/src/lib/sub-bots/sub-bots.js:52:30)
nodetest_1  |
nodetest_1  |   2) sub-bots/sub-bots.js log a subBot in and out subBot module should accept bot to log out:
nodetest_1  |      TypeError: bot.destroy is not a function
nodetest_1  |       at Object.logout (src/lib/sub-bots/sub-bots.js:21:13)
nodetest_1  |       at Context.<anonymous> (test/src/lib/sub-bots/sub-bots.js:57:21)

two:

nodetest_1  |   3 failing
nodetest_1  |
nodetest_1  |   1) sub-bots/sub-bots.js log a subBot in and out bot should have logged in correctly:
nodetest_1  |      AssertionError: expected false to be true
nodetest_1  |       at Context.<anonymous> (test/src/lib/sub-bots/sub-bots.js:52:30)
nodetest_1  |
nodetest_1  |   2) sub-bots/sub-bots.js log a subBot in and out subBot module should accept bot to log out:
nodetest_1  |      TypeError: bot.destroy is not a function
nodetest_1  |       at Object.logout (src/lib/sub-bots/sub-bots.js:21:13)
nodetest_1  |       at Context.<anonymous> (test/src/lib/sub-bots/sub-bots.js:57:21)
nodetest_1  |
nodetest_1  |   3) sub-bots/sub-bots.js test passBot rejection due to exceeded limit "before all" hook:
nodetest_1  |      Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

Plus a crash sometimes:

nodetest_1  | [5:53:37 PM] [ERROR] (!play) Sub bot encountered an error, TypeError: Cannot read property 'members' of null
nodetest_1  | [CRITICAL_ERROR] (logger) alertChannel null, crashing
nodetest_1  | npm info lifecycle [email protected]~test: Failed to exec test script
nodetest_1  | npm ERR! Test failed.  See above for more details.
digdiscord_nodetest_1 exited with code 1

Update - Another crash:

nodetest_1  | - Last Events:
nodetest_1  | - [6:15:47 PM] (Channel Positions) constructPositions
nodetest_1  | - [6:15:47 PM] (Channel Positions) indexTextChannels
nodetest_1  | - [6:15:47 PM] (Crash Handler) crash
nodetest_1  | - Last Messages Recieved:
nodetest_1  | - [6:15:47 PM] (Testserverorbit) !help full
nodetest_1  | - [6:15:47 PM] (Testserverorbit) !ping
nodetest_1  | - [6:15:47 PM] (Testserverorbit) !ping
nodetest_1  | - TypeError: Cannot read property 'channels' of null
nodetest_1  |     at indexTextChannels (/var/project/src/lib/admin/channels/positions.js:140:37)
nodetest_1  |     at constructPositions (/var/project/src/lib/admin/channels/positions.js:76:5)
nodetest_1  |     at Object.globalCheck (/var/project/src/lib/admin/channels/positions.js:41:13)
nodetest_1  |     at Object.checkPositions (/var/project/src/lib/admin/channels/channelsMaster.js:45:19)
nodetest_1  |     at Timeout.startchecks [as _onTimeout] (/var/project/src/lib/admin/admin.js:96:18)
nodetest_1  |     at ontimeout (timers.js:365:14)
nodetest_1  |     at tryOnTimeout (timers.js:237:5)
nodetest_1  |     at Timer.listOnTimeout (timers.js:207:5)
nodetest_1  | [CRITICAL_ERROR] (logger) alertChannel null, crashing
nodetest_1  | npm info lifecycle [email protected]~test: Failed to exec test script
nodetest_1  | npm ERR! Test failed.  See above for more details.

I've said before tests failing then passing on repeats is generally a sign of bad test code rather than bad library code but I think the best way to solve these is to set repeats to 0 and be quite strict on anything that starts to cause trouble because it's going to harm the CI process

Maelstromeous:
Changed milestones to Stable release. We need this fixing because we can claim V1.

Seeing these errors in practically every Jenkins log:

  1) bot-live-tests Commands parsing tests "before each" hook for "should reply `!help`":
     TypeError: Cannot read property 'sendMessage' of null
      at Object.stub (node_modules/sinon/lib/sinon/stub.js:41:64)
      at Context.<anonymous> (test/src/bot.js:34:19)

  2) bot-live-tests Commands parsing tests "after each" hook for "should reply `!help`":
     TypeError: Cannot read property 'sendMessage' of null
      at Context.<anonymous> (test/src/bot.js:41:20)

  3) sub-bots/sub-bots.js log a subBot in and out bot should have logged in correctly:
     AssertionError: expected false to be true
      at Context.<anonymous> (test/src/lib/sub-bots/sub-bots.js:52:30)

  4) sub-bots/sub-bots.js log a subBot in and out subBot module should accept bot to log out:
     TypeError: bot.destroy is not a function
      at Object.logout (src/lib/sub-bots/sub-bots.js:21:13)
      at Context.<anonymous> (test/src/lib/sub-bots/sub-bots.js:57:21)

  5) sub-bots/sub-bots.js test passBot rejection due to exceeded limit should reject if feature disabled:

      AssertionError: expected 'All sub bots are currently busy' to deeply equal 'The maximum number of subBots are currently running'
      + expected - actual

      -All sub bots are currently busy
      +The maximum number of subBots are currently running
      
      at Context.<anonymous> (test/src/lib/sub-bots/sub-bots.js:108:27)

A lot of these issue are now gone with the CI built into the staging server running on it's own set of bots. However, there are the odd occasional issues which causes tests to fail, and these need to be ironed out before V1.

 1 failing

  1) commands/stats.js test timestamps stats should show pingtime calculated of message timestamps:

      AssertionError: expected -1 to not deeply equal -1
      + expected - actual

      
      at Context.<anonymous> (test/src/lib/commands/stats.js:144:81)

Legacy Issue: Add ban/kick abilities to the bot commands

Original issue by James:

Discord's own perms are less than ideal. With a command like "!ban atperson[time]" we could easily control the length of time certain roles are able to ban for unlike discords very binary system

Add commands:
!ban atmember [time]
!kick atmember

Ban times maybe something like:
Staff - Perm (Limitless)
Leader - Up to 24h (5 a day limit)
Officer - Up to 6h (3 a day limit)

[Proposal] Integrate Redis and MongoDB

So this is kind of a large proposal as it requires some changes to make this happen. The start would be to include Redis and MongoDB and create a stack of these services and the Bot.

The reason is to include both is to persist data long term and make crashes less problematic. For instance when the bot crashes the list of people with a mute role gets wiped. MongoDB will be the store for server settings and things like user data, then we don't need the hardcoded settings for instance. Redis can be used as out jobs queue(like the play command), then when the bot crashes and restarts it can basically start where it left off(it can be possible that crashes can happen because of this data, which means when this data is used there should be a loose interpretation).

For MongoDB I know of a excellent ODM called Mongoose. The benefit choosing this over something like Mysql is that it will safe us some time short term and give us a more maintainable database.

Addition of these services would also require us to make some changes. Particularly to how we handle the configuration. For a start most of the configuration will just go from the files to the database and can be loaded in when the application starts. Other configurations like tokens, keys, connection details, etc will get default values which we will be able to overwrite using a special configuration file(for development) and environment variables. The environment variables will give us an easy way to link the different services to each other and have the possibility to overwrite them if necessary.

Create staging server

A new discord server must be created that is a perfect mirror of the current DIG server.

Unlike developer branches where we run automated tests and test our own features manually, the staging branch is as close to a beta as our project has. On staging we test all features in a patch, make sure they're working together and it's our last chance to catch any bugs before an update gets pushed to live.

Setting up staging requires that whoever is setting it up is able to see all the channels on the live discord to ensure the servers match.

Set up CI systems

Both passing tests and enforced code style should be automatically parsed by CI systems. Coverage should also be reported on however as not all code is testable this will not be automatically enforced.

This should be completed before we start working on continued development

Fix versioning in package.json

As part of our bug fix patch, we should fix (in the static sense) the versions of dependencies in the package.json file. A lot of dependencies are currently optimistically versioned which can cause stability issues and has actually done so for DIGBot in the past.

This issue will require fixing the dependencies to their latest stable versions and then testing their functionality.

This work should hopefully be completed early on in our bug smashing phase

Legacy Issue: Events - Scheduled events triggering via web hooks

Original issue by Maelstromeous:

The fact we're running off hard coded events is rather... insanity.

We really should be pulling these from a database, and executing JSON requests to the bot which will enable it to create the channels nessessary. The web server should then send a request at the end of the event instructing the bot to remove the channels.

I would like the bot NOT to be integrating with the database directly. It's not only a security risk (as someone could do dodgy shit via commands if we manage to code it like that), but it will add a ton of bloat to the bot.

This is how it would go down:

Web server running PHP runs the a PHP script, on a scheduled basis (probably via a Jenkins job set to run every 5 mins)
Said script then does the hard work of pulling events out of the database
If the scenario is correct, the script will then compose a JSON request to the bot.
The bot receives this request, and then creates the various channels required for the event.
After the event time has expired, the PHP will compose another JSON request which instructs the bot to delete the channels.
This means that the bot will be stripped of all this manual checking of times etc, as the scheduling is performed by the server (i.e. Jenkins / Cronjob) and all the checking is done "server side" with PHP. The bot will purely just create and delete channels.

Example JSON message to create event

{
    "type": "createEventChannels",
    "channels": [
        {
            "name": "DIGT/Ops/1",
            "type": "voice"
        },
        {
            "name": "digt-ops",
            "type": "text"
        }
    ],
    "roles": [
        "90092974523826176", "200995317024292865", "189767484495233024"
    ],
    "name": "DIGT Monday Ops",
    "description": "DIGT Monday Ops are casual, expect farming and casually led squads. All are welcome, usually held on TS at ts.dignityofwar.com",
    "notifications": [
        {
            "server": "123456789",
            "channel": "123456789"
        }
    ]
}

Maelstromeous:
I could build a PHP script that sends the JSON webhook on a predetermined basis. We would have to strip out all the processing code and only have the box post to the Channel on an event by event basis. The bot would then turn into basically simply spit out the event in the events channel, create the requested channels and delete them, and do nothing else. All event processing stuff would be then done on the server and by extension Bolt. This allows users on the website to create events on a predetermined set of instructions such as dates, title, time etc period we would have to figure out how to do repeated events but that should be simple enough to hard code temporarily within the PHP script.

All of the wording of the events and stuff like that can be done via a property that the user sets rather than being a predetermined message set by us. However for now hard coding it into the PHP script is sufficient.

Maelstromeous:
This will now be handled by the API. The API will run a cronjob and send a JSON call to DIGBot to do announcements etc.

CI method of rewriting environment variables inefficient

In docker/CISetup.sh we currently use 26 seconds of Travis build time to rewrite the 13 environment variables we need. This is currently accomplished in 13 separate lines by creating and rewriting 13 separate json files. I am not certain but I think it is more likely than not there is a much more efficient way to accomplish this task, the code in question:

jq -c '.token = $newVal' --arg newVal $token $configFile > tmp.$$.json && mv tmp.$$.json $configFile

jq -c '.subBots.subBot1.id = $newVal' --arg newVal $ID1 $configFile > tmp.$$.json && mv tmp.$$.json $configFile
jq -c '.subBots.subBot2.id = $newVal' --arg newVal $ID2 $configFile > tmp.$$.json && mv tmp.$$.json $configFile
jq -c '.subBots.subBot3.id = $newVal' --arg newVal $ID3 $configFile > tmp.$$.json && mv tmp.$$.json $configFile
jq -c '.subBots.subBot4.id = $newVal' --arg newVal $ID4 $configFile > tmp.$$.json && mv tmp.$$.json $configFile
jq -c '.subBots.subBot5.id = $newVal' --arg newVal $ID5 $configFile > tmp.$$.json && mv tmp.$$.json $configFile
jq -c '.subBots.subBot6.id = $newVal' --arg newVal $ID6 $configFile > tmp.$$.json && mv tmp.$$.json $configFile

jq -c '.subBots.subBot1.token = $newVal' --arg newVal $token1 $configFile > tmp.$$.json && mv tmp.$$.json $configFile
jq -c '.subBots.subBot2.token = $newVal' --arg newVal $token2 $configFile > tmp.$$.json && mv tmp.$$.json $configFile
jq -c '.subBots.subBot3.token = $newVal' --arg newVal $token3 $configFile > tmp.$$.json && mv tmp.$$.json $configFile
jq -c '.subBots.subBot4.token = $newVal' --arg newVal $token4 $configFile > tmp.$$.json && mv tmp.$$.json $configFile
jq -c '.subBots.subBot5.token = $newVal' --arg newVal $token5 $configFile > tmp.$$.json && mv tmp.$$.json $configFile
jq -c '.subBots.subBot6.token = $newVal' --arg newVal $token6 $configFile > tmp.$$.json && mv tmp.$$.json $configFile

Legacy Issue: !play phase 2™

This issue requires a refactor of the play.js file, this is by far the most complicated code in our bot. For your own sanity only attempt if you have a good grasp of node.js

Still it's one of the most loved features of our bot and better volume control is probably the number 1 request so I'd love to get some work done on this once we're stable

Original issue by James:

Gunna leave this for at least a week maybe much longer while I collect things that need doing with the feature, edit OP with things that need looking at

  • Gueren no yojo or whatever it is that drags on so long I'll cut that from the "fun" playlist, or maybe swap to its TV version
  • Bad blood in 10's playlist is an instrumental... This is what happens when you only listen to the first 4 secs of songs, I guess people will have to sing it for now
  • Pass on coded playlist volumes, not as consistent as I'd like (Wait till discord.js v12, maybe will fix global stream volumes) [v12 would you believe it is still not out, they may have fixed this in a minor release]
  • See if it's possible to get song names for YT video requests (should not be too hard)
  • See if it's possible to get song names for YT playlist requests (I'd guess this'd be a lot harder)
  • See if anti duplication can remember the array index provided immediately prior with larger arrays to improve rotation. Up to 10?
  • Have bot playback stop automatically if all members leave the channel
  • Make sure replies are sent to all commands
  • Make sure to let people know if requests are bad
  • Have a good look at the code and make sure we don't have any processing/memory black holes
  • Make sure to tell people if they're doing silly things like including a &t= timestamp
  • Allow multiplications to channel volumes instead of just up and down (enforce absolute limit)
  • Investigate if it's possible to have the bot swap between channels on request
  • Investigate playlist sequential/shuffle modes
  • Investigate songs randomly skipping before they're finished
  • Allow !play queue, to display queue in channel

Maelstromeous:
You should certainly be able to get the video title, would be sufficient.

James:
Good amount of time passed, this is however gunna be dependent on discord.js v12 so I'll postpone until it's out

Maelstromeous:
What in particular is dependant on v12?

James:
General stability plus volume overhaul, connection, playback and random crashes should all hopefully be fixed but it'll be massively breaking apparently so I kinda wanna wait to overhaul it

Maelstromeous:
Okies

Enable CI test coverage reports

It would be nice to have reports of what lines of code are covered by tests and whether PRs are well tested enough. A tool such as coveralls could be used to do this, this would in most cases require a slight refactor of Travis code to compile a coverage report and send it to a CI coverage handler for analysis.

This can be pretty complicated and isn't essential so it's not necessary for our v0.1 infrastructure patch

Legacy Issue: Add Community Town Hall announcment

Original issue by Maelstromeous:

Would be nice to have DIGBot announce the community town hall a week in advance so people can get their suggestions in.

Will have to figure out how to get the last Sunday of the month. In PHP it would be a breeze but in JS it's more difficult.

Could also announce the staff meeting too to all game leaders an hour before expected start

This was a very nice idea and I would like to see a few mentions sent out to people to let them know when meetings are happening in a few days then again in a few hours

Channel positions enforcement disabled

Position enforcement temporarily disabled. I think it may be behaving slightly weirdly as it was designed before subchannels (topics maybe? The way channels are grouped on discord now) were a thing.

As with the MCS it would be worth asking the community staff if they wish to retain this feature before removing/updating it

Legacy Issue: Re-balance commands filter

Original issue by Maelstromeous:
Need to go through the command and see what things should actually be strictly enforced, the polls and maybe text based things like !catfacts or !lmgtfy don't really need to be strictly limited to the commands channel I don't think

Unlock !poll command and its answers from #digbot

James:
Eddited the issue to expand from !poll to entire module re-balancing things that go well in text like lmgtfy for example shouldn't be forced into a channel to cut down on command spam as they're not really spam but part of the conversation

Legacy Issue: All edited in mentions are counted as user mentions

Original issue by James:

If someone tries to edit in a mention either legitimately or attempting to circumvent the limit we still detect and count it. However, we're unable to distinguish between user and role mentions atm.

This was a discord.js bug and has been fixed in more recent versions. Bumping discord.js may fix this without any need for other edits in code

Legacy Issue: Change event start calculation using minutes from start of week to event start

Original issue by Maelstromeous:

Currently, there's an issue James has reported where we can't have events that start any time between 00:00 and 00:30 due to a check that validates the date of today and the date of any events.

A better solution, in my opinion of course, would be to do a by-minute calculation where 0 is the first minute of the week. Consider the following pseudocode:

var dow = new Date().getDay();

var nowInMinutes = (dow * 60) * 24;

foreach event {
    var eventStartMinutes = (event.day.startHour * 60) * 24;

    // Calculate if now is within a 5+- minute range of the start of the event
    if (nowInMinutes > (eventMinutes - 5) && nowInMinutes < (eventMinutes + 5)) {
        // Do shit
    }
}

Note: Above is NOT functional code.

Above goes through each event and calculates if the current time in minutes is within the startMinutes - 5, and within startMinutes + 5. Therefore, this gives the bot a 10 minute window to detect it's start.

Ideally the bot should be configured to run every minute to lower this margin.

James:
What if someone wants to start an event at 00:00 Monday

Maelstromeous:
Then it would execute at 00:05 or less, hence the +-5 minutes incase that ever happens

That is if the script is run every minute or so.

James:
Note: The hardcode module is a temporary measure until we can intergrate the events into our website database, which should hopefully be soonTM. If there was a tag bellow 'low priority' this issue would get it

Maelstromeous:
I'd say it's more of a reminder to make sure we account for this when we get round to doing the event system properly. Might even be we don't have the bot doing the calculations but the website creating the events and the bot merely creating channels and whatnot.

Set up deployment infrastructure

We need a set up where changes to the staging and master branches are automatically deployed.

How this will run entirely depends on how Llama chooses to set up our hosting

Legacy Issue: Superprune feature

Original Issue by Maelstromeous:

Depends on #39 [editted the issue number here of course]

Extend the functionality where if we've not seen a member online over X amount of days, even with roles, remove them from the server and notify #staff.

Legacy Issue: Event problems

Original issue by James:

Auto deletion was broken again for event channels.

Also the non-functioning MCS naming structure was pushed to live, "DIGT/Ops/1-e-" please adapt MCS or revert or disable

Maelstromeous:
We still need to figure out some kind of persistence mechanism for the events. At the moment, when the bot gets restarted, all the checks for event channels, etc go out of the window.

James:
Might be worth revisiting channel.lastMessageID, I think stability of those properties were much improved in V11, I think it'd be far better to do that if we can before we go the database route. I'll open a separate issue to check that though

Related crashes:

[ERROR] (Crash Handler) [6:43:21 PM] Uncaught Exception Crash
- Last Messages Recieved:
- [6:35:18 PM] (Dignity of War) who cares about streams
- [6:35:23 PM] (Dignity of War) I just want the basics
- [6:35:41 PM] (Dignity of War) It's likely we won't make the move to the forum for another half a year anyway
- [6:35:47 PM] (Dignity of War) We're just getting the foundation in place
- [6:39:46 PM] (Dignity of War) https://github.com/flagrow/flarum-api-client
Seems a bit inactive (might get updated if flarum actually needs changes in the API) but its relatively simply coded so we can fork it if needed. Looks like a neat interface to use for flarum
- TypeError: server.getChannel is not a function
    at alert (/var/www/dignityofwar.com/bot/src/lib/admin/events.js:48:16)
    at prehourcheck (/var/www/dignityofwar.com/bot/src/lib/admin/events.js:115:13)
    at Object.module.exports.check (/var/www/dignityofwar.com/bot/src/lib/admin/events.js:23:21)
    at Timeout.fiveMinCheck [as _repeat] (/var/www/dignityofwar.com/bot/src/lib/admin/admin.js:69:12)
    at Timeout.wrapper [as _onTimeout] (timers.js:417:11)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)

James:
This has been left broken for a month now, it's a primary cause of bot instability, as no work has been made towards fixing it should we just disable events entirely until we're running it off the database as planned? Work should be beginning on that soon

Maelstromeous:
Do we know if this is still broken?

James:
Has been crashing the bot 3 times a week for 5 weeks now.

6:30:47 PM [INFO] (Channels Master) The channel digt-ops-feedback-e- was deleted upon creation as it held an identical name and type to an existing channel
6:30:47 PM [WARNING] (Crash Handler) Unhandled Rejection: Error: Not Found
6:35:44 PM [ERROR] (Hard Coded Events) Unable to find eventlength for event channel: ⏰ DIGT/Ops/Lounge-e-

Maelstromeous:
Probably crashing due to using emoji icons now

James:
Part of the problem yes, but like 10% of the problem it's a one line fix. The module got majorly messed up by 128 [A notorious issue that became a gigantic refactor of how memory was stored (server.js was created here)] and hasn't been fixed since

Maelstromeous:
Righto. We'll just have to endure.

Legacy Issue: Add twitch stream API intergration

Original issue by James:

We currently use streambot to post to the #streams channel when one of our member's stream goes live. We can use the twitch API to integrate this feature in our own bot.

Twitch:
https://github.com/justintv/twitch-api

This issue was actually surprisingly difficult, 2 developers made failed attempts at it. It also requires an API token. I have the community one for the bot and can provide it for testing purposes on request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.