PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/core.js

https://gitlab.com/CarimA/NitxBotDiscord
JavaScript | 209 lines | 138 code | 10 blank | 61 comment | 10 complexity | be2480f82ec406659c660d13ee1c2d46 MD5 | raw file
  1. 'use strict';
  2. let fs = require('fs');
  3. let os = require('os');
  4. let pastemd = require('pastemd');
  5. let hastebin = require(`${APPPATH}/lib/hastebin`);
  6. let utils = require(`${APPPATH}/lib/utils.js`);
  7. module.exports = {
  8. startup: (app) => {
  9. },
  10. onchat: (user, userID, channelID, message, event, callback) => {
  11. },
  12. commands: [
  13. {
  14. aliases: [ 'about' ],
  15. description: 'Posts a summary of information about the bot.',
  16. action: (user, userID, channelID, event, args, callback) => {
  17. callback({
  18. to: channelID,
  19. message: `I am NitxBot 2 (Now Discord-flavoured!), a smarter bot made in NodeJS. I am plugin-based, allowing content creators full freedom over any aspect of my functionality.`
  20. });
  21. }
  22. },
  23. {
  24. aliases: [ 'git', 'source', 'sourcecode' ],
  25. description: 'Posts a link to the GitLab repository for the bot.',
  26. action: (user, userID, channelID, event, args, callback) => {
  27. callback({
  28. to: channelID,
  29. message: `GitLab repository: **https://gitlab.com/CarimA/NitxBotDiscord**`
  30. });
  31. }
  32. },
  33. {
  34. aliases: [ 'idea', 'bugreport', 'suggestion', 'suggest', 'complaint' ],
  35. description: 'Makes a report to the developer.',
  36. usage: '{ message }',
  37. action: (user, userID, channelID, event, args, callback) => {
  38. if (args && args.length >= 1) {
  39. callback({
  40. to: '243527173200281601',
  41. message: `From ${user}#${userID}: ${args.join(', ')}`
  42. });
  43. callback({
  44. to: channelID,
  45. message: 'Thank you for your idea/bug report. Please do continue to suggest ideas or report problems.'
  46. });
  47. } else {
  48. callback({
  49. to: channelID,
  50. message: 'Usage: -idea {message}'
  51. });
  52. }
  53. }
  54. },
  55. {
  56. aliases: [ 'invite' ],
  57. description: 'Provides a link that allows you to invite NitxBot to your own server.',
  58. action: (user, userID, channelID, event, args, callback) => {
  59. callback({
  60. to: channelID,
  61. message: `Want me to come to your own server? Head on to https://discordapp.com/oauth2/authorize?client_id=223144453555224578&scope=bot and select your server under the dropdown menu and hit *Authorize*. Note that you require **Manage Server** permissions in order to invite me somewhere!`
  62. });
  63. }
  64. },
  65. {
  66. aliases: [ 'pin', 'pass', 'password', 'passcode', 'code' ],
  67. description: 'Generates a PIN between 0000 and 9999.', // If arguments are provided only the users provided will be messaged the PIN.',
  68. //usage: '-pin «comma-separated users (eg. @NitxBot, @Carim)»',
  69. action: (user, userID, channelID, event, args, callback) => {
  70. let min = 0;
  71. let max = 9999;
  72. let pin = utils.blockify(("0" + (Math.floor(Math.random() * (max - min + 1)) + min)).substr(-4));
  73. if (event.d.mentions.length > 0) {
  74. // only message these people
  75. for (let i = 0; i < event.d.mentions.length; i++) {
  76. callback({
  77. to: event.d.mentions[i].id,
  78. message: `Your randomly generated **PIN** is ${pin}`
  79. });
  80. }
  81. callback({
  82. to: userID,
  83. message: `Your randomly generated **PIN** is ${pin}`
  84. });
  85. } else {
  86. callback({
  87. to: channelID,
  88. message: `Your randomly generated **PIN** is ${pin}`
  89. });
  90. }
  91. //if (args && args.length > 0) {
  92. //} else {
  93. //}
  94. }
  95. },
  96. {
  97. aliases: [ 'eval', 'evaluate', 'js' ],
  98. whitelist: [ '104711168601415680' ],
  99. description: 'Evaluates a JavaScript expression.',
  100. usage: '{ expression }',
  101. action: (user, userID, channelID, event, args, callback) => {
  102. try {
  103. callback({
  104. to: channelID,
  105. message: JSON.stringify(eval(args.join(', ')))
  106. });
  107. } catch(error) {
  108. callback({
  109. to: channelID,
  110. message: `Error: [${error.name}: ${error.message}]`
  111. });
  112. }
  113. }
  114. },
  115. {
  116. aliases: [ 'shutdown', 'kill' ],
  117. whitelist: [ '104711168601415680' ],
  118. description: 'Shuts down the bot.',
  119. action: (user, userID, channelID, event, args, callback) => {
  120. process.exit(-1);
  121. }
  122. },
  123. {
  124. aliases: [ 'say' ],
  125. whitelist: [ '104711168601415680' ],
  126. description: 'Allows a message to be sent through the bot.',
  127. usage: `{ channel ID }, { message }`,
  128. action: (user, userID, channelID, event, args, callback) => {
  129. if (!args || args.length <= 1) {
  130. callback({
  131. to: channelID,
  132. message: 'Usage: -say {channel id}, {message}'
  133. })
  134. return;
  135. }
  136. callback({
  137. to: args[0],
  138. message: args.join(', ')
  139. });
  140. }
  141. }/*,
  142. {
  143. aliases: [ 'answer', 'tellme' ],
  144. description: 'Sends a query to Wolfram Alpha answering any question.',
  145. usage: `{ query }`,
  146. action: (user, userID, channelID, event, args, callback) => {
  147. wolfram.query(args.join(', '), (error, result) => {
  148. if (error) {
  149. callback({
  150. to: channelID,
  151. message: `<@${userID}>, an error occured. Unable to answer.`
  152. });
  153. } else {
  154. if (result.length === 0) {
  155. callback({
  156. to: channelID,
  157. message: `<@${userID}>, no results were found.`
  158. });
  159. return;
  160. }
  161. callback({
  162. to: channelID,
  163. message: `<@${userID}>, here is your answer`
  164. });
  165. for (let i = 0; i < result.length; i++) {
  166. if (result[i].primary) {
  167. callback({
  168. to: channelID,
  169. message: `**${result[i].title}**: ${result[i].subpods[0].value}`
  170. });
  171. }
  172. }
  173. }
  174. });
  175. }
  176. }/*,
  177. {
  178. aliases: [ 'logs' ],
  179. whitelist: [ '104711168601415680' ],
  180. description: 'Provides a link of bot logs.',
  181. action: (user, userID, channelID, event, args, callback) => {
  182. hastebin(utils.getLogs(), (error, url) => {
  183. if (error) {
  184. utils.error(error);
  185. } else {
  186. callback({
  187. to: channelID,
  188. message: `Logs uploaded to **${url}**`
  189. });
  190. utils.info('Uploaded logs to: ' + url);
  191. }
  192. });
  193. }
  194. }*/
  195. ]
  196. };