269 Commits
Author SHA1 Message Date
rich 1153d1919c fixing indents 2021-04-04 15:01:48 -04:00
rich 499d86459b Merge branch 'testing' of https://gitlab.rickelobe.com/Bots/r0b3BOT into testing 2021-04-04 14:54:55 -04:00
rich c053b58733 not properly handling non jason response 2021-04-04 14:54:38 -04:00
rich e018cfa05b Merge branch 'master' of https://gitlab.rickelobe.com/Bots/r0b3BOT into testing 2021-03-23 19:11:00 -04:00
rich 9f58177559 Merge branch 'dev' into 'master'
Bring in fix for displaying correct version number

See merge request Bots/r0b3BOT!63
2021-03-22 14:40:18 +00:00
rich 58e1781397 correctly fixing the version now (wish the documentation was better) 2021-03-22 00:10:35 +00:00
rich f08eb06db4 Fixing the version information displayed for the info command 2021-03-22 00:06:43 +00:00
rich 807bf17f61 Merge branch 'dev' into 'master'
Merge MMR checker into master for release

See merge request Bots/r0b3BOT!62
2021-03-21 23:42:04 +00:00
rich 3e354d3655 Merge MMR checker into master for release 2021-03-21 23:42:04 +00:00
rich fa38734869 Merge branch 'testing' into 'dev'
Merge MMR Checker into Dev

See merge request Bots/r0b3BOT!61
2021-03-21 23:29:08 +00:00
rich 66ed4fd4d1 Merge MMR Checker into Dev 2021-03-21 23:29:07 +00:00
rich c528e0f638 Added new feature 2021-03-21 17:19:27 +00:00
rich 41b1c73ff3 adding back bot.remove_command entry 2021-03-21 13:10:16 -04:00
rich b1d1a7b1cc Cleanup of code 2021-03-21 13:07:25 -04:00
rich 8bb132be24 Organizing 2021-03-21 12:44:49 -04:00
rich 15d0a01dcb typo 2021-03-21 12:37:56 -04:00
rich ad05b2f427 updating help command details 2021-03-21 12:37:20 -04:00
rich 2cbaef99c0 working on mmrstatus 2021-03-21 12:26:25 -04:00
rich a53cab8343 working on mmrstatus 2021-03-21 12:24:03 -04:00
rich e00da20870 Cleaning up output text 2021-03-21 12:17:00 -04:00
rich 45d8d5702c found typo 2021-03-21 12:11:24 -04:00
rich 86e7944837 editing output for clarity 2021-03-21 12:05:31 -04:00
rich e9a2165f78 found some issues 2021-03-21 11:41:45 -04:00
rich 9421b22cff was using wrong varibale... missed ong 2021-03-21 07:54:10 -04:00
rich 5767d2d606 was using wrong varibale 2021-03-21 07:53:06 -04:00
rich 3b5ecf4b6b more debug 2021-03-21 07:46:56 -04:00
rich d961698d40 typo 2021-03-21 07:45:15 -04:00
rich 37e9512d82 troubleshooting -list command 2021-03-21 07:44:27 -04:00
rich 5e1164d98c typo 2021-03-20 19:25:50 -04:00
rich 1e64e992dd let's try it this way 2021-03-20 19:25:05 -04:00
rich 667126c916 dunno 2021-03-20 19:18:31 -04:00
rich 5ada6cfb36 troubleshooting response check: welp, had that backwards 2021-03-20 19:13:08 -04:00
rich b6d5ce6836 troubleshooting response check: fixing syntax 2021-03-20 19:11:16 -04:00
rich 0077f1a80b troubleshooting response check 2021-03-20 19:09:34 -04:00
rich dfa82dbe96 correcting variable being used 2021-03-20 19:06:59 -04:00
rich ba014f4c98 fixing... 2021-03-20 19:05:27 -04:00
rich 6823161897 fixing... 2021-03-20 19:03:52 -04:00
rich fcb0051c87 fixing 2021-03-20 19:03:15 -04:00
rich 403aa9a362 check if handle was actually found 2021-03-20 19:00:42 -04:00
rich 8d91336b43 Added mmrstatus command 2021-03-20 18:31:41 -04:00
rich 25abfb2a59 updating info command 2021-03-20 18:23:30 -04:00
rich 3f9a976742 clarifying alert text 2021-03-20 17:17:49 -04:00
rich 8f41991a3d fixing assignment again... hopefully for the last time, again 2021-03-20 16:31:09 -04:00
rich 1785162cea fixing assignment again... hopefully for the last time 2021-03-20 16:30:15 -04:00
rich 0207424d32 fixing assignment again 2021-03-20 16:28:50 -04:00
rich ab7009e43f fixing assignment 2021-03-20 16:25:36 -04:00
rich 5c0e61d466 adding newlines 2021-03-20 12:51:43 -04:00
rich 2cabbbf6f1 more tweaks to output 2021-03-20 12:49:19 -04:00
rich 803e8d552d more tweaks to output 2021-03-20 12:48:19 -04:00
rich 0950092f6d more tweaks to output 2021-03-20 12:46:47 -04:00
rich f6e15d9c35 output formatting 2021-03-20 12:38:21 -04:00
rich 5b917e032f fixing minor typo 2021-03-20 12:16:36 -04:00
rich 7628f8d1ae setting variable to int 2021-03-20 12:14:52 -04:00
rich 1e496efbee added interval option for mmr checker, cleaned up some output 2021-03-20 12:11:30 -04:00
rich 0cf348570b tweaks 2021-03-20 11:39:17 -04:00
rich 55419dbafb correcting syntax error 2021-03-20 10:03:45 -04:00
rich cf3757ce11 added enable/disable check before starting mmr checker and statping monitor 2021-03-20 10:02:08 -04:00
rich 4cf45b2684 added enable/disable options for mmr checker and statping monitor 2021-03-20 10:01:34 -04:00
rich 544f7b5833 I think all of the necessary changes have been made to add the mmr checker... needs to test now? 2021-03-19 22:43:02 -04:00
rich fa2a34c951 adding mmr api variable 2021-03-19 22:24:04 -04:00
rich affbf366a1 adding base code for mmr_checker 2021-02-14 21:37:17 -05:00
rich 4056f60cd8 duplicated statping functions for mmr monitor 2021-01-20 21:55:42 -05:00
rich a7a36f123c Merge branch 'dev' of https://gitlab.rickelobe.com/Bots/r0b3BOT into mmr_checker 2021-01-20 21:27:43 -05:00
rich 6865041707 Added missing playtime value for rs command 2020-09-02 09:47:06 -04:00
rich 520758e2f2 Added Wiz Khalifa clip $big 2020-07-01 09:10:58 -04:00
rich cd74624747 added iran sound clip 2020-07-01 08:58:15 -04:00
rich 525f13b3e8 Merge branch 'dev' into 'master'
changing play delay to check if file is still being played

See merge request Bots/r0b3BOT!60
2020-06-22 11:36:18 -04:00
rich c82dc32ca2 changing play delay to check if file is still being played 2020-06-19 11:42:37 -04:00
rich ccb260c3f9 Merge branch 'master' into 'testing'
Make testing master again!

See merge request Bots/r0b3BOT!59
2020-04-15 15:27:09 -04:00
rich fa9fb6b27d Merge branch 'dev' into 'master'
Version 0.3

See merge request Bots/r0b3BOT!58
2020-04-15 15:09:06 -04:00
rich b222b2342e Update README.md - added links to octoprint and statping pages 2020-04-15 15:05:43 -04:00
rich a0d5c63aee moved image 2020-04-15 14:56:58 -04:00
rich 0976c2c9e3 Update README.md 2020-04-15 14:55:40 -04:00
rich 82647b2597 Screenshot of command list 2020-04-15 14:53:58 -04:00
rich e20ac2c849 Update README.md 2020-04-15 14:53:12 -04:00
rich 37a689e58e added screenshot of service alert 2020-04-15 14:46:01 -04:00
rich 79043feb91 Upload screenshot of service alert 2020-04-15 14:44:40 -04:00
rich c2f905229f Updated README.md, listing more features 2020-04-15 14:43:31 -04:00
rich 114e6aeb9b Merge branch 'testing' into 'dev'
Merge changes to fix Issue #8

See merge request Bots/r0b3BOT!57
2020-04-14 22:02:58 -04:00
rich 83f7270d6b updated help message 2020-04-14 21:59:10 -04:00
rich 63602bc19c wasnt saving the result, doh 2020-04-14 21:57:31 -04:00
rich 65a608395b adding code to allow inserting _ in place of spaces and will revert 2020-04-14 21:55:00 -04:00
rich f11c076258 trying removal of print statement 2020-04-14 21:52:41 -04:00
rich 7b7f57f4c0 trying more ' 2020-04-14 21:50:55 -04:00
rich e2c100c5bb removing " from service variable 2020-04-14 21:48:16 -04:00
rich 57e5c37f1a Merge branch 'testing' into 'dev'
changed channel to currentsub_req[1]

See merge request Bots/r0b3BOT!56
2020-04-14 21:24:36 -04:00
rich d53cc3b3f6 changed channel to currentsub_req[1] 2020-04-14 21:18:00 -04:00
rich fc7ef5eb69 Merge branch 'testing' into 'dev'
testing changes ready for dev

See merge request Bots/r0b3BOT!54
2020-04-14 20:48:21 -04:00
rich ccba129bb2 Merge branch '7-info-should-list-a-version-identifier' into 'testing'
Resolve "$info should list a version identifier"

See merge request Bots/r0b3BOT!53
2020-04-14 20:46:45 -04:00
rich d9f52bdafd Merge branch 'testing' into 'dev'
testing of version information completed, merge into dev

See merge request Bots/r0b3BOT!52
2020-04-14 20:40:23 -04:00
rich f0615c51e8 Merge branch '7-info-should-list-a-version-identifier-2' into 'testing'
Resolve "$info should list a version identifier"

See merge request Bots/r0b3BOT!51
2020-04-14 20:37:19 -04:00
rich 6deb4455ed minor console output text change 2020-04-14 20:31:37 -04:00
rich 86d7e414c2 forgot {} 2020-04-14 20:27:40 -04:00
rich 19304b5d27 adding version to info command 2020-04-14 20:23:42 -04:00
rich f87a07f6bd Merge branch 'testing' into 'dev'
Fixed redundant Statping Monitor starts

See merge request Bots/r0b3BOT!50
2020-04-14 13:38:15 -04:00
rich 6b3490557c move start of statping monitor out from bot.on_ready. Think it was being start multiple times when bot reconnected to discord. 2020-04-14 13:38:15 -04:00
rich 006468bd35 Merge branch 'dev' into 'testing'
# Conflicts:
#   r0b3bot.py
2020-04-14 13:37:43 -04:00
rich 2cf516dd1f move notice of statping mon start 2020-04-14 13:29:16 -04:00
rich 0467fde122 missing attribute 2020-04-14 13:27:35 -04:00
rich d9362fb819 rearrange to fix 2020-04-14 13:22:50 -04:00
rich b165e67676 update 2020-04-14 13:20:52 -04:00
rich 1dc54fa5f2 testing output 2020-04-14 13:19:33 -04:00
rich 91063db833 change criteria 2020-04-14 13:15:43 -04:00
rich c9f2d07f4b syntax 2020-04-14 13:12:59 -04:00
rich 290bdc3903 adding debug output 2020-04-14 13:12:27 -04:00
rich 93734ec773 pemdas 2020-04-14 13:11:14 -04:00
rich 37a6b08fe2 changed logic 2020-04-14 13:07:39 -04:00
rich f1e35bae27 added sleep 2020-04-14 12:57:40 -04:00
rich 5c2b426748 moving 2020-04-14 12:56:10 -04:00
rich ed6606f8ac case? 2020-04-14 12:54:30 -04:00
rich be4b46a81d changed to global, though I dont think that's the cause of the issue 2020-04-14 12:52:52 -04:00
rich f0c65454d3 moved start of statping monitor back to on_ready, but am now checking started state variable. 2020-04-14 09:01:19 -04:00
rich 646081286f move start of statping monitor out from bot.on_ready. Think it was being start multiple times when bot reconnected to discord. 2020-04-14 08:47:07 -04:00
rich e36d8727c5 added print statements for sending alerts 2020-04-14 08:39:16 -04:00
rich e8cf0f2c24 Merge branch 'testing' into 'dev'
Testing

See merge request Bots/r0b3BOT!48
2020-04-13 22:42:40 -04:00
rich cd4b3bbb38 Testing 2020-04-13 22:42:40 -04:00
rich 2a5ced954b added new commands to help 2020-04-13 22:39:19 -04:00
rich ea2a76bf81 adding breaks 2020-04-13 22:30:09 -04:00
rich 1be2590f43 adding another break 2020-04-13 22:09:54 -04:00
rich f37fc95ddc added break 2020-04-13 22:07:37 -04:00
rich 2515eb83a5 changed when assigning service name 2020-04-13 22:04:34 -04:00
rich 47e5c364a9 calling wrong variable 2020-04-13 22:00:46 -04:00
rich a03efbd2a9 fix indent 2020-04-13 21:59:24 -04:00
rich d49d368895 saving updated file 2020-04-13 21:58:55 -04:00
rich ba792ff1f5 moving indent out 2020-04-13 21:57:15 -04:00
rich faad238f8c fix wrong vairable assignment 2020-04-13 21:54:43 -04:00
rich cc1368258c fixing typo 2020-04-13 21:53:10 -04:00
rich 7c1b3c207d changing option 2020-04-13 21:51:55 -04:00
rich 8f9af7d10c addd -del option 2020-04-13 21:48:57 -04:00
rich 4ec07fdf77 changed info command prefix to variable 2020-04-13 21:34:45 -04:00
rich 7e9be22734 changed spalert to spstatus 2020-04-13 21:32:31 -04:00
rich d85149e5f1 seriously if this was it... ugh 2020-04-13 21:29:41 -04:00
rich 0e393b089f typo 2020-04-13 21:25:32 -04:00
rich c16fb46b78 does this work? 2020-04-13 21:24:13 -04:00
rich f051fe0087 undo 2020-04-13 21:20:01 -04:00
rich bf2ac43a88 typo 2020-04-13 21:18:50 -04:00
rich 87f82af697 ugh 2020-04-13 21:18:17 -04:00
rich 9036557154 trying a different method 2020-04-13 21:08:32 -04:00
rich c9c67f32c9 typo? 2020-04-13 21:05:53 -04:00
rich cc90375376 using .update to append 2020-04-13 21:05:02 -04:00
rich 6df3f8a55f doing it wrong 2020-04-13 21:01:16 -04:00
rich 0bf0134a86 changin variable 2020-04-13 20:59:54 -04:00
rich 576f21b6fc was not handling when serivce was not present in file 2020-04-13 20:58:36 -04:00
rich 824c952ad9 moved statement outside of loop 2020-04-13 20:54:17 -04:00
rich eeae88595d adding more console output 2020-04-13 20:52:30 -04:00
rich a709f25ea3 added consonle output 2020-04-13 20:48:37 -04:00
rich 4c43ab0e8e added placeholder 2020-04-13 20:44:33 -04:00
rich d97a2d1fe3 need to query before use 2020-04-13 20:43:51 -04:00
rich 10baa139a1 fix statement 2020-04-13 20:39:35 -04:00
rich be04db6237 fixing indents 2020-04-13 20:39:06 -04:00
rich ce319f8696 added spsub- list 2020-04-13 20:38:29 -04:00
rich b26139fdac fixing append of channel id 2020-04-13 20:13:41 -04:00
rich 98cf67381b adding response 2020-04-13 20:07:28 -04:00
rich 132267f5d4 adding more console output, fixed missing ' 2020-04-13 20:05:03 -04:00
rich 1a204d303b fixing iteration 2020-04-13 20:02:47 -04:00
rich f82227ea0d adding notice to channel of duplicate 2020-04-13 19:57:56 -04:00
rich 238bb9f5ea fixing dict creation 2020-04-13 19:55:48 -04:00
rich f026c88817 change how saving channel 2020-04-13 19:00:27 -04:00
rich fa2fb34e41 moved print 2020-04-13 18:56:24 -04:00
rich 85cf5f5ce5 added confirmation message 2020-04-13 18:53:08 -04:00
rich 1e62920925 typo 2020-04-13 18:51:09 -04:00
rich d58c7245e7 clearing up console output 2020-04-13 18:50:25 -04:00
rich 861397b455 fixing append 2020-04-13 18:41:11 -04:00
rich a265de4a62 fixing typo 2020-04-13 18:34:44 -04:00
rich d9883b6f97 fixing iteration 2020-04-13 18:33:45 -04:00
rich 64d80c79ac change to ctx.channel 2020-04-13 18:31:11 -04:00
rich 91def4cd4d working on fixing iterations 2020-04-13 18:26:47 -04:00
rich 6a46983293 changed wording for clarity 2020-04-13 18:23:09 -04:00
rich 0544d870e7 fixed call 2020-04-13 18:22:27 -04:00
rich e1327961b6 fixed 2020-04-13 18:19:44 -04:00
rich 153bc39e63 moved to single line 2020-04-13 18:18:38 -04:00
rich f94f69aa59 change debug 2020-04-13 18:10:38 -04:00
rich 9dfae705e5 now accounting for status not found response 2020-04-13 17:23:42 -04:00
rich 32144c5657 fixed comparison 2020-04-13 17:18:52 -04:00
rich 5235df2259 init status 2020-04-13 17:08:58 -04:00
rich eca6fae897 removed use of new_ 2020-04-13 17:04:48 -04:00
rich 1e58d5017d adding debug 2020-04-13 16:59:14 -04:00
rich 75121c5a79 printing status varibale 2020-04-13 16:28:56 -04:00
rich 71231d3a9b testing variable 2020-04-13 16:24:56 -04:00
rich 3b6c82d6f5 fixed iteration 2020-04-13 16:19:14 -04:00
rich 1fc96f6b3a adding debug print 2020-04-13 16:17:00 -04:00
rich c7216563e6 changing assignment type 2020-04-12 23:56:36 -04:00
rich 4a27acb4ac updated for loop 2020-04-12 23:53:42 -04:00
rich e0d77bf82d forgot closing ] 2020-04-12 23:49:50 -04:00
rich 84e6f8ed6d changing assignment 2020-04-12 23:49:02 -04:00
rich 67309f5925 adding debug output 2020-04-12 23:45:26 -04:00
rich 8480215db9 changing assignment 2020-04-12 23:43:16 -04:00
rich 7bab9a1238 setting protocol to 4 2020-04-12 23:38:56 -04:00
rich e08621d317 saving pickled dict 2020-04-12 23:38:09 -04:00
rich 204acac19c now adding key 2020-04-12 23:35:07 -04:00
rich 077e82bda2 reworked StatPing_Montor to use dict 2020-04-12 23:28:05 -04:00
rich 9af4a52927 reqrote spsub_T to use/create a nested dictionary 2020-04-12 23:11:49 -04:00
rich 2970adc634 using pickle again 2020-04-12 21:08:47 -04:00
rich a95b88d99f no bytes 2020-04-12 20:52:14 -04:00
rich 3832d13200 saving just channel id and now appending 2020-04-12 20:50:38 -04:00
rich ca06fea13f trying different library 2020-04-12 15:28:06 -04:00
rich 5575dbb054 case update 2020-04-12 15:18:45 -04:00
rich 8d02152697 more typo fixes 2020-04-12 15:16:54 -04:00
rich ae601c45f5 typo 2020-04-12 15:15:52 -04:00
rich 7391e68778 replace pickle with aiofile 2020-04-12 15:14:12 -04:00
rich 0f607f67ee more awaits? 2020-04-12 15:04:55 -04:00
rich 142a7fcf48 forgot awaits 2020-04-12 14:59:07 -04:00
rich 2ef6cf6053 Added new test functions to read in spsubs from file 2020-04-12 14:54:35 -04:00
rich dd0dbb0f27 formatting 2020-04-12 11:13:56 -04:00
rich f85a637566 added read in of command prefix and updated bot creation to use config. Also moved bot object creation to after read in of prefix config 2020-04-11 12:20:09 -04:00
rich bb711b8167 fixed missing ' in console output 2020-04-11 12:15:34 -04:00
rich 9f4ee76bb7 added bot_command_prefix to config file 2020-04-11 12:15:13 -04:00
rich 4464d589d9 change notices to embed w/ color 2020-04-10 14:26:09 -04:00
rich de815af682 wording changes 2020-04-10 14:12:33 -04:00
rich 46dc4190a0 added send to channel notifying service is now being monitored 2020-04-10 14:11:10 -04:00
rich c8414ba000 replaced sleep w/ more friendly versions 2020-04-10 14:07:45 -04:00
rich 9eaf1d8029 added some console outputs 2020-04-10 14:02:59 -04:00
rich b26af574ae fixed variable name 2020-04-10 13:24:51 -04:00
rich 51692a17db should probably rework this if elif statements 2020-04-10 13:22:13 -04:00
rich b90b5fc8f4 type 2020-04-10 13:20:13 -04:00
rich 6e0642a11b cant assign when declaring 2020-04-10 13:19:27 -04:00
rich fba8cc680c initial test of alert subscriptions 2020-04-10 13:15:59 -04:00
rich 1547784a40 removed ctx 2020-04-10 12:12:51 -04:00
rich 3b65435899 moving outside of loop 2020-04-10 12:10:57 -04:00
rich bd98d1bdcb more reworking of functions for future needs 2020-04-10 12:08:16 -04:00
rich d946067bd4 forgot await 2020-04-10 11:51:30 -04:00
rich d15267ea53 reworking functions 2020-04-10 11:49:43 -04:00
rich 05b7520a3f help text grammar 2020-04-09 23:56:36 -04:00
rich f8e04ea086 for mendo 2020-04-09 23:50:43 -04:00
rich e594d27beb removed uptime command and added spalert to $help 2020-04-09 23:40:19 -04:00
rich 427937e8d5 added $ hint in status 2020-04-09 23:37:50 -04:00
rich ff189b7357 added reply if service was not found 2020-04-09 23:26:57 -04:00
rich 92542b4405 code cleanup 2020-04-09 23:23:25 -04:00
rich 351fb9c090 commenting out debug 2020-04-09 23:13:28 -04:00
rich af6862dfe5 forgot : 2020-04-09 23:12:52 -04:00
rich 4e562c5c66 reworked if else statements 2020-04-09 23:12:31 -04:00
rich 25d0aad3cb fixed indent 2020-04-09 23:07:35 -04:00
rich 82743a0d66 dump status of all services 2020-04-09 23:06:24 -04:00
rich ce51483344 remove empty send 2020-04-09 23:05:33 -04:00
rich 40806125a5 added send for debug 2020-04-09 22:59:19 -04:00
rich bb33e9f82b moved to beginning of cmd 2020-04-09 22:54:01 -04:00
rich 7fdbcdf951 assigning properly 2020-04-09 22:52:26 -04:00
rich 369b3bf867 didnt mean to remove this 2020-04-09 22:51:11 -04:00
rich b62f864167 change back to break added spalert value to else 2020-04-09 22:49:33 -04:00
rich 5b748dc207 return 2020-04-09 22:45:54 -04:00
rich cbf96086d3 added break in for loop 2020-04-09 22:43:57 -04:00
rich 29b7cd93da .json() 2020-04-09 22:42:44 -04:00
rich 7987fe186a added .json() 2020-04-09 22:39:42 -04:00
rich 3fd8c5de0e removed slash 2020-04-09 22:33:27 -04:00
rich 82fda0be94 added contenty type 2020-04-09 22:32:37 -04:00
rich 3f9cbf8964 commented json load 2020-04-09 22:30:16 -04:00
rich d86f634827 dump to separate line 2020-04-09 22:26:31 -04:00
rich 82b08ce80b extra ) removed 2020-04-09 22:24:56 -04:00
rich 7015ac4f7e dumping json to channel for debug 2020-04-09 22:24:15 -04:00
rich bf8a306870 making global? 2020-04-09 22:20:22 -04:00
rich 2a3fc39da6 loading as json 2020-04-09 22:17:35 -04:00
rich 079770da7b corrected variable name 2020-04-09 22:15:07 -04:00
rich cabf2d3ba8 added await to cmd call 2020-04-09 22:13:09 -04:00
rich 9f8864683d fixed incorrect variable call 2020-04-09 22:09:57 -04:00
rich 56685916f0 fixed typo 2020-04-09 22:08:25 -04:00
rich 991e0f2429 ugh this is shameful, another syntax issue 2020-04-09 22:07:26 -04:00
rich 89235209e1 fixed yet another syntax error else if to elif 2020-04-09 22:06:16 -04:00
rich 66ff3375ff fixed unexpected indent 2020-04-09 22:04:47 -04:00
rich 993adfc196 fixed typo 2020-04-09 22:03:17 -04:00
rich fdbe058c2a Adding ability to query statping for service status 2020-04-09 22:00:04 -04:00
rich 4471e5930d Change server to url 2020-04-09 21:27:41 -04:00
rich 1c7c739942 added statping_server as a config variable 2020-04-07 21:01:19 -04:00
rich 0a7eec666d added comment for statping api key 2020-04-07 17:17:12 -04:00
rich 41c640ca10 Added statping API key variables 2020-04-07 17:12:09 -04:00
rich 2e961db66f added $heavy command 2020-03-30 21:24:09 -04:00
rich c0d817fb69 Added yaw command 2020-03-30 21:01:26 -04:00
rich 6d1b82d3c3 added uptime to $info command 2020-03-30 12:38:22 -04:00
rich 8805587576 add gitlab link to $info command 2020-03-29 19:00:46 -04:00
rich a8e62c5ce9 Merge branch 'dev' into 'master'
Version 0.2

See merge request Bots/r0b3BOT!47
2020-03-29 18:20:14 -04:00
10 changed files with 786 additions and 68 deletions

No files matched your search

Vendored
BIN
View File
Binary file not shown.
+15 -6
View File
@@ -2,11 +2,20 @@
[![pipeline status](http://gitlab.rickelobe.com/Bots/r0b3BOT/badges/master/pipeline.svg)](http://gitlab.rickelobe.com/Bots/r0b3BOT/commits/master)
# Screenshot
![](images/Discord_Printstat_Command.png)
# Description
This is R0b3's Discord Bot. It's creation was basically a challenge posed a coworker who said "Hey, you can write Discord Bots in Python... Make one to display your 3D printer status!".
This is R0b3's Discord Bot. It's creation was basically a challenge posed a coworker who said "Hey, you can write Discord Bots in Python... Make one to display your 3D printer status!". But as time went on, a few more features were added. Aside from being able to query and monitor your 3D printer, it can also fetch the current status of a service monitroed by your [StatPing](https://github.com/statping/statping) instance. In addition to just fetching the current status of a service, you can subscribe to receive alerts for any StatPing service state change. All subscriptions are persistent and will remain even after the bot is restarted.
# Features
* Query & Monitor 3D Printer Status using `$printstat` command(Requires that your printer is connected to [Octoprint](https://octoprint.org/))<br>
![](images/Discord_Printstat_Command.png)
* Query serivces states on StatPing using the `$spstatus`
* Use `$spsub` to "Subscribe" to service change alerts for StatPing services. Subscribed alerts are persistent and are not lost on bot restart.<br>
![Example service alert](images/Service_alert.png)
* Use `$mmrsub` to "Subscribe" to a League of Legends handle's Ranked Average. As with the StatPing feature, the subscriptions are persistent.
* Play a selection of sound clips to voice channel members using the various commands (`$torololo`, `$oops`, `$promoted`, etc)
# Commands
![Screenshot of $help](images/command_list.png)
# Requirements
1. discord.py version 1.2.4 or greater<br>
@@ -14,6 +23,6 @@ This is R0b3's Discord Bot. It's creation was basically a challenge posed a cow
# Configuration
1. Create a Discord Bot via Developer tools<br>
2. Enter various configuration parameters in bot_config.conf.example<br>
2. Enter configuration parameters in bot_config.conf.example<br>
3. Enter OctoPrint config parameters in octoapi.conf.example<br>
4. Rename *.example files as *.conf<br>
4. Rename *.example files as *.conf and setup your config<br>
+10 -1
View File
@@ -3,14 +3,23 @@
# Replace the placeholders with your information. Do not use quotes.
#
# discord_auth_token - this is the bot token generated via the Discord development console.
# bot_command_prefix - The prefix used identify commands for this bot
# hass_url - URL to your home assistant instance. This is used to turn on the light by your 3d printer
# hass_token - Long Lived Access Token used to authenticate with the REST API for your Home assistant instance
# hass_light - Entity name of the light you want to control
# octoprint_ip_address - IP Address of you OctoPrint (or OctoPi) host. Used to get 3D printer stats.
# statping_url - Server hostname of the StatPing instance we will be querying w/ the REST API
# statping_api_key - API Key for Statping to query for service status
#
discord_auth_token = <Discord Auth Token>
bot_command_prefix = <!/$/#/etc>
hass_url = <URL to HomeAssistant>
hass_token = <HomeAssistant Long Lived Access Token>
hass_light = <Entity_ID of the light @ your printer>
octoprint_ip_address = <OctoPrint IP Address>
statping_enable = <trues/false>
statping_url = <Statping URL>
statping_api_key = <Statping API Key>
mmr_checker_enable = <true/false>
mmr_checker_interval = <number of seconds between checks>
mmr_api_url = <MMR API URL>
Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

+761 -61
View File
@@ -2,39 +2,47 @@
import discord
from discord.ext import commands
from discord import FFmpegPCMAudio
from discord.utils import get
from discord.voice_client import VoiceClient
from datetime import datetime
import urllib.request
import random
import os
import sys
import octoapi
import time
from datetime import datetime
import configparser
import json
from discord import FFmpegPCMAudio
from discord.utils import get
from discord.voice_client import VoiceClient
import requests
import asyncio
bot = commands.Bot(command_prefix='$', description='A derpy derp of a bot.')
import aiofiles as aiof
import pickle
#Record the time the bot started
start_time = time.time()
start_time = time.time()
config = configparser.RawConfigParser()
configFilePath = r'bot_config.conf'
# Last error message variable used by $last_error command to display in discord
global last_error
last_error = "No errors been recorded."
try:
config.read(configFilePath)
except:
print("Error loading config! Please check config file 'bot-config.conf'")
# Setup HomeAssistant URL and Headers
# Last error message variable used by $last_error command to display in discord
global last_error
last_error = "No errors have been recorded."
#
# Assign bot config from setting in config file
#
# Assign Bot core settings
DISCORD_AUTH_TOKEN = config.get('bot-config', 'discord_auth_token')
BOT_COMMAND_PREFIX = config.get('bot-config', 'bot_command_prefix')
# 3D Printer Setup - HomeAssistant URL and Headers & OctoPrint
HASS_TOKEN = config.get('bot-config', 'hass_token')
HASS_URL = config.get('bot-config', 'hass_url')
HASS_LIGHT = config.get('bot-config', 'hass_light')
@@ -43,28 +51,82 @@ hassHEADERS = {
'Authorization': f"Bearer {HASS_TOKEN}",
'content-type': 'application/json',
}
OCTOPRINT_IP_ADDRESS = config.get('bot-config', 'octoprint_ip_address')
DISCORD_AUTH_TOKEN = config.get('bot-config', 'discord_auth_token')
# StatPing Monitor Settings
statping_enable = config.get('bot-config', 'statping_enable')
STATPING_URL = config.get('bot-config', 'statping_url')
STATPING_API_KEY = config.get('bot-config', 'statping_api_key')
statpingURL = STATPING_URL + "/api/services"
statpingHEADERS = {
'Authorization': f"Bearer {STATPING_API_KEY}",
'content-type': 'application/json',
}
#MMR Checker Settings
mmr_checker_enable = config.get('bot-config', 'mmr_checker_enable')
mmr_checker_interval = config.get('bot-config', 'mmr_checker_interval')
mmrURLBASE = config.get('bot-config', 'mmr_api_url')
mmrHEADERS = {
'User-Agent': 'Linux:com.r0b3bot:v.01a',
'content-type': 'application/json',
}
# Configure bot
bot = commands.Bot(command_prefix=BOT_COMMAND_PREFIX, description='A derpy derp of a bot.')
bot.remove_command('help')
# Printing configuration details to console
print(f"HomeAssistant URL: {hassURL}")
print(f"HomeAssistant URL HEADERS: {hassHEADERS}")
print(f"HomeAssistant Light: {HASS_LIGHT}")
print(f"OctoPrint IP Address: {OCTOPRINT_IP_ADDRESS}")
print("=== 3D Printer Status config ===")
print(f" HomeAssistant URL: {hassURL}")
print(f" HomeAssistant URL HEADERS: {hassHEADERS}")
print(f" HomeAssistant Light: {HASS_LIGHT}")
print(f" OctoPrint IP Address: {OCTOPRINT_IP_ADDRESS}")
print("\n=== StatPing Monitor Config ===")
print(f" Enabled: {statping_enable}")
print(f" Server: {STATPING_URL}")
print(f" API Key: {STATPING_API_KEY}")
print(f" URL Headers: {statpingHEADERS}")
print("\n=== MMR Checker Config ===")
print(f" Enabled: {mmr_checker_enable}")
print(f" Checker Interval: {mmr_checker_interval}")
print(f" API URL BASE: {mmrURLBASE}")
# On Ready
@bot.event
async def on_ready():
print("\n:::: Config Loaded ::::\n")
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
print("Setting activity to 'Listenting to your commands")
activity = discord.Activity(name="your commands",type=discord.ActivityType.listening)
print(f" User: {bot.user.name}")
print(f" ID: {bot.user.id}")
print(f"\n\n")
print(f"Setting activity to 'Listenting to your {BOT_COMMAND_PREFIX}commands'")
activity = discord.Activity(name=f"your {BOT_COMMAND_PREFIX}commands",type=discord.ActivityType.listening)
await bot.change_presence(activity=activity)
# If 15 seconds or less have passed since the program was started, start the monitor.
runtime = time.time() - start_time
if runtime <= 15:
#Run StatPing_Monitor
if statping_enable == 'True':
print("Statping Monitor enabled, starting StatPing Monitor.")
await StatPing_Monitor()
else:
print(f">> Bot has been running for more than {int(runtime)} seconds. Not starting StatPing Monitor.")
#Run MMR Montor
if runtime <= 15:
if mmr_checker_enable == 'True':
print("MMR Checker enabled, starting MMR Checker.")
await MMR_Monitor()
else:
print(f">> Bot has been running for more than {int(runtime)} seconds. Not starting MMR Checker.")
print(">> Startup complete.")
@bot.command()
async def greetings(ctx):
await ctx.send(":smiley: :wave: Hello there!")
@@ -72,6 +134,7 @@ async def greetings(ctx):
@bot.event
async def on_command_error(ctx, error):
global last_error
if isinstance(error, commands.CommandOnCooldown):
seconds = round(error.retry_after,1)
print(f" - Error, user tried to use command while in cooldown (wait is: {seconds}")
@@ -93,21 +156,6 @@ async def on_command_error(ctx, error):
async def last_error(ctx):
await ctx.send(f"Last error recorded: {last_error}")
@bot.command()
async def uptime(ctx):
# Displays how long the bot has been online
second = time.time() - start_time
minute, second = divmod(second, 60)
hour, minute = divmod(minute, 60)
day, hour = divmod(hour, 24)
week, day = divmod(day, 7)
week = int(week)
day = int(day)
hour = int(hour)
minute = int(minute)
second = int(second)
await ctx.send(f"Uptime [WW:DD:HH:MM:SS]: {week:02d}:{day:02d}:{hour:02d}:{minute:02d}:{second:02d}")
#
# Giphy Commands
#
@@ -200,6 +248,26 @@ async def aww(ctx, member : discord.Member="NONE"):
async def eia(ctx, member : discord.Member="NONE"):
await play_sound(ctx, member, "./sounds/awesome.mp3", "$eia", 11)
@bot.command()
@commands.cooldown(rate=1, per=10.0, type=commands.BucketType.user)
async def yaw(ctx, member : discord.Member="NONE"):
await play_sound(ctx, member, "./sounds/yaw.mp3", "$yaw", 6)
@bot.command()
@commands.cooldown(rate=1, per=10.0, type=commands.BucketType.user)
async def heavy(ctx, member : discord.Member="NONE"):
await play_sound(ctx, member, "./sounds/heavy.mp3", "$heavy", 6)
@bot.command()
@commands.cooldown(rate=1, per=10.0, type=commands.BucketType.user)
async def iran(ctx, member : discord.Member="NONE"):
await play_sound(ctx, member, "./sounds/iran.mp3", "$iran", 4)
@bot.command()
@commands.cooldown(rate=1, per=10.0, type=commands.BucketType.user)
async def big(ctx, member : discord.Member="NONE"):
await play_sound(ctx, member, "./sounds/big.mp3", "$big", 4)
@bot.command()
@commands.cooldown(rate=1, per=10.0, type=commands.BucketType.user)
async def rs(ctx, member : discord.Member="NONE"):
@@ -207,7 +275,7 @@ async def rs(ctx, member : discord.Member="NONE"):
datestring = datestring.strftime("%m/%d/%Y-%H:%M:%S")
if ctx.message.channel.is_nsfw():
soundfiles = ["./sounds/leeroy.mp3","./sounds/monkey_bitch.mp3","./sounds/More_cowbell.mp3","./sounds/BoomBitch.mp3","./sounds/Promoted.mp3","./sounds/Trololo.mp3","./sounds/Oops.mp3"]
await play_sound(ctx, member, random.choice(soundfiles), "$rs")
await play_sound(ctx, member, random.choice(soundfiles), "$rs", 6)
else:
print(f"[{datestring}]: {ctx.message.author.display_name} called $rs, but is not in a NSFW channel")
await ctx.send("This command is too explicit for you!")
@@ -261,7 +329,9 @@ async def play_sound(ctx, member : discord.Member, soundFile, command, playtime)
print(f" - Playing {soundFile}")
time.sleep(1)
voice.play(audio_source, after=None)
time.sleep(playtime)
while voice.is_playing():
await asyncio.sleep(1)
#time.sleep(playtime)
print(f" - Disconnecting from '{channel}'")
await voice.disconnect()
###
@@ -497,7 +567,6 @@ async def updateStatus():
activity = discord.Activity(name="your commands",type=discord.ActivityType.listening)
await bot.change_presence(activity=activity)
@bot.command()
async def info(ctx):
embed = discord.Embed(title="R0b3BOT", description="Derpy Derp of a Bot :P", color=0xeee657)
@@ -511,34 +580,665 @@ async def info(ctx):
# give users a link to invite thsi bot to their server
embed.add_field(name="Invite", value="[Invite link](https://discordapp.com/api/oauth2/authorize?client_id=416312716677087233&permissions=51264&scope=bot)")
# Bot Uptime
second = time.time() - start_time
minute, second = divmod(second, 60)
hour, minute = divmod(minute, 60)
day, hour = divmod(hour, 24)
week, day = divmod(day, 7)
week = int(week)
day = int(day)
hour = int(hour)
minute = int(minute)
second = int(second)
embed.add_field(name="Uptime [WW:DD:HH:MM:SS]:", value=f"{week:02d}:{day:02d}:{hour:02d}:{minute:02d}:{second:02d}", inline=False)
print("Getting git describe data to display as version in info embed")
bot_version = await run('git describe --tags')
embed.add_field(name="Version:", value=f"{bot_version}", inline=False)
# Gitlab link to source
embed.add_field(name="Source Code:", value="[R0b3Bot on Gitlab](https://gitlab.rickelobe.com/Bots/r0b3BOT)", inline=False)
await ctx.send(embed=embed)
bot.remove_command('help')
@bot.command()
async def spstatus(ctx, service = "NONE"):
if service != "NONE":
#await get_stp_status(ctx, service.lower())
result = await get_stp_status(service.lower())
if result == "service not found":
await ctx.send(f"'{service}' was not found")
elif result['online']:
await ctx.send(f"{result['name']} is Online")
elif not result['online']:
await ctx.send(f"{result['name']} is Offline")
else:
await ctx.send(f"Received an unexpected result '{result}' querying '{service}'")
else:
await ctx.send("Please speficy a service name to query.")
@bot.command()
async def spsub(ctx, service = "NONE"):
spsublist = {} # Statping Subscription list to be read in from file
# Structure of spsublist nested dictionary
# spsublist[service name][list of channel ids][a state value]
# dict = {'Plex': {'state' : 'online', 'channels' : ['1232', '43234']}
# 'Space Eingineers' : {'state' : online', 'channels' : ['2343', '54563']}}
#
currentsub_request = [] # list of elements detailing the current sub request
datestring = datetime.now()
datestring = datestring.strftime("%m/%d/%Y-%H:%M:%S")
# replace _ with sapces
service = service.replace("_"," ")
print(f"[{datestring}]: {ctx.message.author.display_name} called '$spsub '{service}'''")
# Only work on this if the user has supplied a service name to monitor, a value of NONE
# means nothing was specified
if service != "NONE" and service != "-list" and not service.startswith('-del '):
print(f">> Querying status of '{service}' to see if it exists")
service_state = await get_stp_status(service)
if service != "NONE":
if service == "-list":
# List the serivces that this channel is subscribed to
# Read in spsublist
sublist = ''
async with aiof.open('spsublist.dat', 'rb') as datafile:
pickled_spsublist = await datafile.read()
spsublist = pickle.loads(pickled_spsublist)
for service in spsublist.keys():
for channel in spsublist[service]['channels']:
if channel == ctx.channel.id:
sublist += f"'{service}' "
await ctx.send(f"This channel is subscribed to: {sublist}")
elif service.startswith('-del:'):
# Delete the service from this channels subscriptions
service_toremove = service[5:]
print(f"{service_toremove}")
# Open the data file for read in
async with aiof.open('spsublist.dat', 'rb') as datafile:
pickled_spsublist = await datafile.read()
spsublist = pickle.loads(pickled_spsublist)
# We haven't found either the channel or servic; mark as false
found_service = False
found_channel = False
# Iterate through the service names in the data
for service in spsublist.keys():
# If the service we want to unsub from is the same as the service in the data, we need to search for the channel
if service.lower() == service_toremove.lower():
# We've found the service match, mark as true
found_service = True
# Iterate through the channels that are subbed to this service
for channel in spsublist[service]['channels']:
# If a channel listed in the service matches the current users channel id, we've found our match
if channel == ctx.channel.id:
# Marking channel as found
found_channel = True
# Get the proper name of the service
service_toremove = service
#Remove the current users channel from this service
spsublist[service]['channels'].remove(ctx.channel.id)
# Break since we're done.
break
# If we got to the point of finding the channel, we're done.
if found_channel:
break
if found_service and found_channel:
print(">> Saving dictionary to spsublist.dat")
async with aiof.open('spsublist.dat', 'wb') as datafile:
pickled_spsublist = pickle.dumps(spsublist, protocol=4)
await datafile.write(pickled_spsublist)
#await datafile.fsync()
await datafile.flush()
await ctx.send(f"This channel is unsubscribed from '{service}' alerts.")
else:
await ctx.send(f"This channel is not subscribed to alerts for '{service_toremove}''")
# If the service exists, proceed with adding it to the list.
elif service_state != "service not found":
print(f">> '{service}' is a valid service on StatPing.")
print(f">> Checking if it has already been subscribed to")
#await ctx.send(f"'{service_state['name']}' added to monitored services")
currentsub_request.append(ctx.channel.id)
currentsub_request.append(service_state['name'])
currentsub_request.append("online")
print(f">> Channel ID: {currentsub_request[0]}")
print(f">> Service Name: {currentsub_request[1]}")
print(f">> Initial State to set: {currentsub_request[2]}")
# read in data file containing dict of subscriptions
print(">> Checking for spsublist.dat")
if os.path.exists('spsublist.dat'):
print(">> Data file exists, reading it in.")
# Read in spsublist
async with aiof.open('spsublist.dat', 'rb') as datafile:
pickled_spsublist = await datafile.read()
spsublist = pickle.loads(pickled_spsublist)
print(f">> Checking if serivce is already in datafile")
found_service = False
found_channel = False
for service in spsublist.keys():
print(f">> Does {service.lower()} == {currentsub_request[1].lower()}")
if service.lower() == currentsub_request[1].lower():
found_service = True
# This service matched what the user is trying to subscribe to
# Now we need to check if this is for the same channel
print(f">> Found {service} in data file, checking for channel")
for channel in spsublist[service]['channels']:
if channel == currentsub_request[0]:
print(f">> This channel is already subscribed to {service}")
await ctx.send(f"This channel is already subscribed to {service} alerts")
found_channel = True
break
if not found_channel:
# Append the current channel id to the list for this service
print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}")
await ctx.send(f"{service} has been added to monitored services for this channel")
spsublist[service]['channels'].append(currentsub_request[0])
break
if not found_service:
# Append the current channel id to the list for this service
print(f">> Adding serivce '{currentsub_request[1]}' to {ctx.channel.id}")
await ctx.send(f"{currentsub_request[1]} has been added to monitored services for this channel")
#newsub = {}
#newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]}
spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]}
else:
print(">> spsublist.dat does not exist, new file will be created")
# append new subscription to dict
print(">> Creating new dictionary")
spsublist[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]}
print(f">> {service} subscription has been saved")
await ctx.send(f"{service} has been added to monitored services for this channel")
#Write updated array to data file
print(">> Saving dictionary to spsublist.dat")
async with aiof.open('spsublist.dat', 'wb') as datafile:
pickled_spsublist = pickle.dumps(spsublist, protocol=4)
await datafile.write(pickled_spsublist)
#await datafile.fsync()
await datafile.flush()
print(">> Done")
#await ctx.send(f"'{service_state['name']}' added to monitored services")
else:
print(f">> '{service}' does not exist, cancelling subscription")
await ctx.send(f"{service} was not found")
async def StatPing_Monitor():
# reads in "spsublist.dat" every 60 seconds then iterates
# through to check for service status changes. This function will need to check
# that "spsublist.dat" exists and is not empty. This function should be called
# in bot.on_ready
#new_spsublist = {}
# read in data file containing list of subscriptions
while True:
print("Statping Monitor: Reading in spsublist.dat")
if os.path.exists('spsublist.dat'):
async with aiof.open('spsublist.dat', 'rb') as datafile:
pickled_spsublist = await datafile.read()
spsublist = pickle.loads(pickled_spsublist)
for service in spsublist.keys():
# service used to be subscription
status = await get_stp_status(service)
print(f">> {service} Online: {status['online']} | Previous state: {spsublist[service]['state']}")
if status != 'status not found':
if status['online'] and spsublist[service]['state'] == 'online':
# nothing has changed, no alert needed
await asyncio.sleep(1)
elif not status['online'] and spsublist[service]['state'] == "offline":
# again, nothing has changed no alert needed
await asyncio.sleep(1)
else:
print(f">> Status of '{service}' has changed, notifying subscribed channels")
if status['online']:
spsublist[service]['state'] = 'online'
for channel in spsublist[service]['channels']:
ctx = bot.get_channel(channel)
print(f">> Alerting {ctx} that {service} is Online")
embed = discord.Embed(title=f"Service Alert", description=f"{service} is Online!", color=0x00ff40)
await ctx.send(embed=embed)
elif not status['online']:
spsublist[service]['state'] = 'offline'
for channel in spsublist[service]['channels']:
ctx = bot.get_channel(channel)
print(f">> Alerting {ctx} that {service} is Offline")
embed = discord.Embed(title=f"Service Alert", description=f"{service} is Offline!", color=0xff2200)
await ctx.send(embed=embed)
else:
for channel in spsublist[service]['channels']:
ctx = bot.get_channel(channel)
print(f">> Alerting {ctx} that {service} is an Unknown state")
embed = discord.Embed(title=f"Service Alert", description=f"{service} is in an unknown state!", color=0xffff00)
await ctx.send(embed=embed)
print(">> Done")
#new_spsublist.append(subscription)
# Write status changes to spsublist.dat
async with aiof.open('spsublist.dat', 'wb') as datafile:
pickled_spsublist = pickle.dumps(spsublist)
await datafile.write(pickled_spsublist)
#await datafile.fsync()
await datafile.flush()
else:
print(">> spsublist.dat does not exist, nothing to do.")
await asyncio.sleep(60)
async def get_stp_status(service):
# Get StatPing status via REST API
spservice_array = requests.get(statpingURL, headers=statpingHEADERS)
found = False
# spservice_array is json data, need to treat it as such
for spservice in spservice_array.json():
# using lower() to eliminate any case mismatch problems
if spservice['name'].lower() == service.lower():
found = True
return spservice
# Want to alert user if the service was not found
if not found:
return "service not found"
#
# Begin functions for MMR sub/alerts
#
@bot.command()
async def mmrstatus(ctx, handle = "NONE"):
print(f">> {BOT_COMMAND_PREFIX}mmrstatus was called for {handle}")
if handle != "NONE":
#await get_stp_status(ctx, service.lower())
result = await get_mmr_status(handle)
if result == "handle not found":
print(f">> {handle} was not found")
await ctx.send(f"'{handle}' was not found. Try wrapping handle in double quotes")
else:
print(f">> {handle} found!")
await ctx.send(f"'{handle}'s Ranked Average is: {result}")
else:
print(f">> User did not speficy handle")
await ctx.send("Please speficy a service name to query.")
@bot.command()
async def mmrsub(ctx, handle = "NONE"):
mmrsublist = {} # MMR Subscription list to be read in from file
# Structure of spsublist nested dictionary
# spsublist[service name][list of channel ids][a state value]
# dict = {'Handle': {'AvgRank' : 'value', 'channels' : ['1232', '43234']}
# 'twtv iddosu2x' : {'AvgRank' : '1082', 'channels' : ['2343', '54563']}}
#
mmrcurrentsub_request = [] # list of elements detailing the current sub request
datestring = datetime.now()
datestring = datestring.strftime("%m/%d/%Y-%H:%M:%S")
# replace _ with sapces
handle = handle.replace("_"," ")
print(f"[{datestring}]: {ctx.message.author.display_name} called '$mmrsub '{handle}'''")
# Only work on this if the user has supplied a service name to monitor, a value of NONE
# means nothing was specified
if handle != "NONE" and handle != "-list" and not handle.startswith('-del '):
print(f">> Querying status of '{handle}' to see if it exists")
handle_state = await get_mmr_status(handle)
if handle != "NONE":
if handle == "-list":
# List the serivces that this channel is subscribed to
# Read in mmrsublist
mmrsublist = ''
async with aiof.open('mmrsublist.dat', 'rb') as datafile:
pickled_mmrsublist = await datafile.read()
sublist = pickle.loads(pickled_mmrsublist)
for handle in sublist.keys():
print(f"current handle: {handle}")
for channel in sublist[handle]['channels']:
print(f">> {channel}")
if channel == ctx.channel.id:
print(f">>>> {channel} == {ctx.channel.id}")
mmrsublist += f"'{handle}' "
await ctx.send(f"This channel is subscribed to: {mmrsublist}")
elif handle.startswith('-del:'):
# Delete the service from this channels subscriptions
handle_toremove = handle[5:]
print(f"{handle_toremove}")
# Open the data file for read in
async with aiof.open('mmrsublist.dat', 'rb') as datafile:
pickled_mmrsublist = await datafile.read()
mmrsublist = pickle.loads(pickled_mmrsublist)
# We haven't found either the channel or servic; mark as false
found_handle = False
found_channel = False
# Iterate through the service names in the data
for handle in mmrsublist.keys():
# If the service we want to unsub from is the same as the service in the data, we need to search for the channel
if handle.lower() == handle_toremove.lower():
# We've found the service match, mark as true
found_handle = True
# Iterate through the channels that are subbed to this service
for channel in mmrsublist[handle]['channels']:
# If a channel listed in the service matches the current users channel id, we've found our match
if channel == ctx.channel.id:
# Marking channel as found
found_channel = True
# Get the proper name of the service
handle_toremove = handle
#Remove the current users channel from this service
mmrsublist[handle]['channels'].remove(ctx.channel.id)
# Break since we're done.
break
# If we got to the point of finding the channel, we're done.
if found_channel:
break
if found_handle and found_channel:
print(">> Saving dictionary to mmrsublist.dat")
async with aiof.open('mmrsublist.dat', 'wb') as datafile:
pickled_mmrsublist = pickle.dumps(mmrsublist, protocol=4)
await datafile.write(pickled_mmrsublist)
#await datafile.fsync()
await datafile.flush()
await ctx.send(f"This channel is unsubscribed from '{handle}' alerts.")
else:
await ctx.send(f"This channel is not subscribed to alerts for '{handle_toremove}''")
# If the service exists, proceed with adding it to the list.
elif handle_state != "handle not found":
print(f">> '{handle}' is a valid Hanlde on Whatismymmr.com.")
print(f">> Checking if it has already been subscribed to")
#await ctx.send(f"'{service_state['name']}' added to monitored services")
mmrcurrentsub_request.append(ctx.channel.id)
mmrcurrentsub_request.append(handle)
mmrcurrentsub_request.append(handle_state)
print(f">> Channel ID: {mmrcurrentsub_request[0]}")
print(f">> Handle: {mmrcurrentsub_request[1]}")
print(f">> Current Ranked Average: {mmrcurrentsub_request[2]}")
# read in data file containing dict of subscriptions
print(">> Checking for mmrsublist.dat")
if os.path.exists('mmrsublist.dat'):
print(">> Data file exists, reading it in.")
# Read in mmrsublist
async with aiof.open('mmrsublist.dat', 'rb') as datafile:
pickled_mmrsublist = await datafile.read()
mmrsublist = pickle.loads(pickled_mmrsublist)
print(f">> Checking if handle is already in datafile")
found_handle = False
found_channel = False
for handle in mmrsublist.keys():
print(f">> Does '{handle}'' == '{mmrcurrentsub_request[1]}'?")
if handle == mmrcurrentsub_request[1]:
found_handle = True
# This service matched what the user is trying to subscribe to
# Now we need to check if this is for the same channel
print(f">> Yes, checking if channel {mmrcurrentsub_request[0]} is already subscribed")
for channel in mmrsublist[handle]['channels']:
if channel == mmrcurrentsub_request[0]:
print(f">> Channel ({mmrcurrentsub_request[0]}) is already subscribed to {handle}")
await ctx.send(f"This channel is already subscribed to {handle} alerts")
found_channel = True
break
if not found_channel:
# Append the current channel id to the list for this service
print(f">> Handle exists, channel not subbed, adding handle '{mmrcurrentsub_request[1]}' to {ctx.channel.id}")
await ctx.send(f"{handle} has been added to monitored handles for this channel")
mmrsublist[handle]['channels'].append(mmrcurrentsub_request[0])
break
if not found_handle:
# Append the current channel id to the list for this service
print(f">> Handle does not exist, adding new entry for '{mmrcurrentsub_request[1]}' to {ctx.channel.id}")
await ctx.send(f"{mmrcurrentsub_request[1]} has been added to monitored handle for this channel")
#newsub = {}
#newsub[currentsub_request[1]] = {'state' : 'online', 'channels' : [currentsub_request[0]]}
mmrsublist[mmrcurrentsub_request[1]] = {'AvgRank' : mmrcurrentsub_request[2], 'channels' : [mmrcurrentsub_request[0]]}
else:
print(">> mmrsublist.dat does not exist, new file will be created")
# append new subscription to dict
print(">> Creating new dictionary")
mmrsublist[mmrcurrentsub_request[1]] = {'AvgRank' : mmrcurrentsub_request[2], 'channels' : [mmrcurrentsub_request[0]]}
print(f">> {handle} subscription has been saved")
await ctx.send(f"{handle} has been added to monitored handles for this channel")
#Write updated array to data file
print(">> Saving dictionary to mmrsublist.dat")
async with aiof.open('mmrsublist.dat', 'wb') as datafile:
pickled_mmrsublist = pickle.dumps(mmrsublist, protocol=4)
await datafile.write(pickled_mmrsublist)
#await datafile.fsync()
await datafile.flush()
print(">> Done")
#await ctx.send(f"'{service_state['name']}' added to monitored services")
else:
print(f">> '{handle}' does not exist, cancelling subscription")
await ctx.send(f"{handle} was not found")
async def get_mmr_status(mmrhandle):
# Get MMR status status via API
#need to replace spaces with %20 before just inserting into URL
mmrhandle.replace(" ", "%20")
mmrURL = ''.join(mmrURLBASE) + mmrhandle
response = requests.get(mmrURL, headers=mmrHEADERS)
try:
mmr_stats = json.loads(response.text)
except ValueError as e:
return "handle not found"
return mmr_stats['ranked']['avg']
async def MMR_Monitor():
# reads in "mmrsublist.dat" every 3 hours then iterates
# through to check for mmr status changes. This function will need to check
# that "spsublist.dat" exists and is not empty. This function should be called
# in bot.on_ready
# read in data file containing list of subscriptions
while True:
print("MMR Monitor: Reading in mmrsublist.dat")
if os.path.exists('mmrsublist.dat'):
async with aiof.open('mmrsublist.dat', 'rb') as datafile:
pickled_mmrsublist = await datafile.read()
mmrsublist = pickle.loads(pickled_mmrsublist)
for handle in mmrsublist.keys():
# service used to be subscription
status = await get_mmr_status(handle)
print(f"{handle} | {mmrsublist[handle]}")
print(f">> '{handle}'s Average Rank: {status} | Previous state: {mmrsublist[handle]['AvgRank']}")
if status != 'handle not found':
if status == mmrsublist[handle]['AvgRank']:
# nothing has changed, no alert needed
await asyncio.sleep(1)
elif not status != mmrsublist[handle]['AvgRank']:
# again, nothing has changed no alert needed
await asyncio.sleep(1)
else:
print(f">> Status of '{handle}' has changed, notifying subscribed channels")
if status > mmrsublist[handle]['AvgRank']:
mmrsublist[handle]['AvgRank'] = status
for channel in mmrsublist[handle]['channels']:
ctx = bot.get_channel(channel)
print(f">> Alerting {ctx} that '{handle}'s Average Rank has Increased!")
embed = discord.Embed(title=f"MMR Alert", description=f"{handle}'s ranked average increased to {status}!", color=0x00ff40)
await ctx.send(embed=embed)
elif status < mmrsublist[handle]['AvgRank']:
mmrsublist[handle]['AvgRank'] = status
for channel in mmrsublist[handle]['channels']:
ctx = bot.get_channel(channel)
print(f">> Alerting {ctx} that '{handle}'s Average Rank has Decreased!")
embed = discord.Embed(title=f"MMR Alert", description=f"{handle}'s ranked average decreased to {status}!", color=0xff2200)
await ctx.send(embed=embed)
else:
for channel in mmrsublist[handle]['channels']:
ctx = bot.get_channel(channel)
print(f">> Alerting {ctx} that {handle}'s rank is an unknown state")
embed = discord.Embed(title=f"MMR Alert", description=f"{handle}'s rank is in an unknown state!", color=0xffff00)
await ctx.send(embed=embed)
print(">> Done")
#new_spsublist.append(subscription)
# Write status changes to spsublist.dat
async with aiof.open('mmrsublist.dat', 'wb') as datafile:
pickled_mmrsublist = pickle.dumps(mmrsublist)
await datafile.write(pickled_mmrsublist)
#await datafile.fsync()
await datafile.flush()
else:
print(">> mmrsublist.dat does not exist, nothing to do.")
# 10800 seconds == 3 hours :)
await asyncio.sleep(int(mmr_checker_interval))
#
#
#
@bot.command()
async def help(ctx):
embed = discord.Embed(title="R0b3BOT", description="List of commands are:", color=0xeee657)
embed.add_field(name="$printstat", value="Uploads a snapshot of Rich's 3D printer and current stats", inline=False)
embed.add_field(name="$explain", value="Displays Dalek EXPLAIN gif", inline=False)
embed.add_field(name="$holyshit", value="Displays Marty McFly HOLY SHIT gif", inline=False)
embed.add_field(name="$greetings", value="Gives a nice greet message", inline=False)
embed.add_field(name="$cat", value="Gives a cute cat gif to lighten up the mood.", inline=False)
embed.add_field(name="$bitch @member", value="Plays clip of BigEric420 saying 'maybe you shouldn't be such a bitch.mp3'", inline=False)
embed.add_field(name="$boom @member", value="Plays 'Boom Bitch' sound clip", inline=False)
embed.add_field(name="$cowbell @member", value="Plays 'SNL More Cowbell' sound clip", inline=False)
embed.add_field(name="$oops @member", value="Plays 'Oops.mp3'", inline=False)
embed.add_field(name="$promoted @member", value="Plays Battlefield Friends 'PROMOTED!' sound clip", inline=False)
embed.add_field(name="$trololo @member", value="Plays a clip of Trololo song", inline=False)
embed.add_field(name="$leeroy @member", value="Plays Leeeerrroooyyy Jenkins clip", inline=False)
embed.add_field(name="$eia @member", value="Plays 'Everything is Awesome' song clip")
embed.add_field(name="$info", value="Gives a little info about the bot", inline=False)
embed.add_field(name="$help", value="Gives this message", inline=False)
embed.add_field(name="$last_error", value="Will display the real error message the bot has last encountered for additional debugging info")
embed.add_field(name="$uptime", value="Displays how long the bot has been up since last service restart")
embed = discord.Embed(title='R0b3BOT Core & Debug Commands:', description="Core commands for info and debug", color=0xeee657)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}info", value="Gives a little info about the bot", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}help", value="Gives this message", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}last_error", value="Will display the real error message the bot has last encountered for additional debugging info")
await ctx.send(embed=embed)
embed = discord.Embed(title="A note about sound clips:", description="Sound clips are only played voice channels. If no user is specified when calling the command, the sound will played in the channel the user is currently joined to. When a username is specified, the bot will play the sound in the channel that user is currently in.")
embed = discord.Embed(title="R0b3BOT Sound Commands", description="To play a sound in a chat channel, use one of the following:", color=0xeee657)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}printstat", value="Uploads a snapshot of Rich's 3D printer and current stats", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}explain", value="Displays Dalek EXPLAIN gif", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}holyshit", value="Displays Marty McFly HOLY SHIT gif", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}greetings", value="Gives a nice greet message", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}cat", value="Gives a cute cat gif to lighten up the mood.", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}bitch @member", value="Plays clip of BigEric420 saying 'maybe you shouldn't be such a bitch.mp3'", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}boom @member", value="Plays 'Boom Bitch' sound clip", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}cowbell @member", value="Plays 'SNL More Cowbell' sound clip", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}oops @member", value="Plays 'Oops.mp3'", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}promoted @member", value="Plays Battlefield Friends 'PROMOTED!' sound clip", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}trololo @member", value="Plays a clip of Trololo song", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}leeroy @member", value="Plays Leeeerrroooyyy Jenkins clip", inline=False)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}eia @member", value="Plays 'Everything is Awesome' song clip")
embed.add_field(name=f"{BOT_COMMAND_PREFIX}heavy @member", value="Plays 'Poppy ooo heavy'")
embed.add_field(name=f"{BOT_COMMAND_PREFIX}iran @member", value="Plays Trump 'I Ran'")
embed.add_field(name=f"{BOT_COMMAND_PREFIX}big @member", value="Plays 'Wiz Khalifa clip'")
await ctx.send(embed=embed)
embed = discord.Embed(title="A note about sound clips:", description="Sound clips are only played in voice channels. If a user is not specified when calling the command, the sound will played in the channel of that issuing user is currently joined to. When a username is specified, the bot will play the sound in the channel that user is currently in.")
await ctx.send(embed=embed)
embed = discord.Embed(title="StatPing Service Monitor Commands", description="Commands for managing the StatPing Service Monitor", color=0xeee657)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}spstatus servicename", value="Retrieves status of service from StatPing")
embed.add_field(name=f"{BOT_COMMAND_PREFIX}spsub service", value="Allows user to subscribe to service status change alerts for the channel. Can replace <service> with -list and -del:service to manage alerts. NOTICE:Replace spaces in service names w/ '_'!")
await ctx.send(embed=embed)
embed = discord.Embed(title="MMR Monitor Commands", description="Commands for managing the MMR Checker", color=0xeee657)
embed.add_field(name=f"{BOT_COMMAND_PREFIX}mmrstatus handle", value="Queries the MMR API for the handle specified and returns the current Ranked Average")
embed.add_field(name=f"{BOT_COMMAND_PREFIX}mmrsub handle", value="Subscribe to receive alerts of ranked average changes for the specified handle. Can run command with just '-list' to list handle the current channel is subbed to. Use -del:service to unsub from a handle. NOTICE:Replace spaces in service names w/ '_'!")
await ctx.send(embed=embed)
# Function to run shell command and return stdout or sterr
async def run(cmd):
proc = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)
stdout, stderr = await proc.communicate()
print(f'[{cmd!r} exited with {proc.returncode}]')
if stdout:
#print(f'[stdout]\n{stdout.decode()}')
return stdout.decode()
if stderr:
#print(f'[stderr]\n{stderr.decode()}')
return stderr.decode()
bot.run(DISCORD_AUTH_TOKEN)
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.