Coder Social home page Coder Social logo

blackhawk-ta / dynobot Goto Github PK

View Code? Open in Web Editor NEW
60.0 6.0 53.0 1.12 MB

Modular Discord bot using JavaScript and optionally Python and Lua.

License: MIT License

JavaScript 97.35% Python 0.66% Lua 1.65% Dockerfile 0.34%
discord-bot discord-js python javascript chatbot modular bot lua nodejs music-bot

dynobot's Introduction

dynoBot

license build github github

End of life

Due to discord's decision to enforce slash commands for bots, I will stop developing this project. This means that I won't fix any issues or bugs nor add new features. The project will remain on GitHub but it will be achieved.

The main reason I took this decision is that converting the bot to use slash commands would require me to rewrite the entire command logic. I neither have the time nor the motivation to rewrite major parts of the code base. On top of that dynoBot is quite maintenance heavy, especially in regard of the music streaming module which depends on a lot of other npm packages that tend to break.

Therefore, I will sadly put this project to rest.

Overview

  1. What is dynoBot
  2. Features
  3. Chat commands
  4. How to use
    1. Set up Discord token
    2. Set up 3rd party api keys
    3. Enable logging
  5. Creating new modules
    1. Chat modules
      1. JavaScript
      2. Python
      3. Lua
    2. Hook modules
      1. JavaScript
      2. Python
      3. Lua
  6. Contribute

What is dynoBot?

dynoBot is a modular Discord bot using JavaScript and optionally also Python and Lua. It is built in a way that creating new modules can be done with ease in a scripting language you prefer.

The idea behind the bot is to create the modules you need by yourself with a minimum amount of effort. Therefore, dynoBot can be considered as a framework which handles everything related to the discord api, so you can immediately start developing your own modules.

Nevertheless, dynoBot can be used without writing a single line of code as long as the included modules are all you need.

Features

The bot has currently following modules:

  • music bot with Spotify, Apple Music and YouTube playlist support
  • remote control rcon game servers
  • currency conversion
  • WolframAlpha calculations
  • send wake-on-lan signals to start servers or other devices in your local network

What commands does the bot have?

You can see all available commands by typing "@BotName help" in the discord chat. Alternatively you can take a look at the commands.json file.

How can I use the bot for my own discord server?

First you need nodejs and optionally python3 for python modules and lua for lua modules. After the installation, clone this repository and run npm install within the dynoBot folder. It should install all required dependencies.

Set up Discord token

To run the discord bot, you'll have to add the security.json file within the directory dynoBot/cfg. It should look like this:

{
	"token": "your discord bot token"
}

IMPORTANT: When you fork this project, don't upload the security.json to your repository. This would allow others to steal your discord token.

Set up 3rd party api keys

If you want to use the Wolfram|Alpha module, you'll need their API key in the security.json as well. You can request a free Wolfram|Alpha API key here.

With the API key, your security.json should look like this:

{
	"token": "your discord bot token",
	"wolframAlphaAPI": "your api key"
}

Enable logging

As a default, all logs are written to the console. If you want the logs to be written to log files, you have to enable logging in the security.json like this:

{
	"token": "your discord bot token",
	"logging": true
}

Now you can start the bot by using the command node main.js within the directory dynoBot.

How can I create new modules?

You can create modules in JavaScript, Python or Lua. There are two types of modules, a chat module and a hook module. A chat module is executed every time a user sends a message with the corresponding command. A hook is automatically executed in a specific interval. Below I will show you how to create them in JavaScript, Python and Lua. Alternatively you can take a look at the example modules for JavaScript, Python and Lua included in the project.

Chat module:

JavaScript, Python and Lua modules need an entry in the commands.json file looking like this:

{
    "group": "command-group-name",
    "type": "python",
    "regex": "py-example|python example",
    "help": "python example",
    "path": "src/py-modules/example-python.py",
    "hidden": false
}

The content of the help property will be used for the command list. If it does not exist, the regex property will be used.

The group property can be used to allow filtering while using the help command. For example there is a group called "basic" including all built-in core commands. If you want to see only commands of the "basic" group in the command list, use " help" instead of the normal help command.

Setting hidden to true will exclude the command from the command list.

JavaScript chat module

The JavaScript module has direct access to the discord.js wrapper. The base structure of a module looks like this:

module.exports = {
	run: function(msg, client) {
		msg.getTextChannel().send("I received these parameters: " + msg.getContentArray());
	}
};

The code executed when the module is called belongs into the run function. The parameters msg and client are by the chatbot-api-wrapper. You can find further information about the implementation there.

Python chat module

The Python module has no access to the discord.js wrapper but gets the msg.contentArray and msg.aRegexGroups. The base structure looks like this:

import sys

msg = sys.argv[1].split(",")  # Array of input parameters
regexGroups = sys.argv[2].split(",")  # Array of input regex groups

# insert code to handle the input parameters here

print("I received these parameters: " + str(msg))  # This will be the msg that the bot sends
print("These are the regex groups" + str(regexGroups))  # This is a second message that the bot sends
sys.stdout.flush()  # cleanup

As you can see, the print makes the bot send a message.

Lua chat module

The Lua module has also no access to the discord.js wrapper but gets the msg.contentArray and msg.aRegexGroups. The base structure looks like this:

-- Import lua module helper for splitting strings into arrays
require "src/utils/luaUtils"

local sMessage = arg[1] -- String of input parameters
local sRegexGroups = arg[2] -- String of input regex groups

local aMessage = utils.splitString(sMessage, ",") -- Array of input parameters
local aRegexGroups = utils.splitString(sRegexGroups, ",") -- Array of input regex groups

-- Insert code to handle the input parameters here

--This will be the msg that the bot sends
print("I received these parameters: [" .. tostring(aMessage[1]) .. ", " .. tostring(aMessage[2]) .. "]")

--This is a second message that the bot sends
print("These are the regex groups: [" .. tostring(aRegexGroups[1]) .. "]")

As you can see, the print makes the bot send a message. Overall Lua modules are pretty similar to Python modules.

Hook module:

JavaScript and Python modules both need an entry in the hooks.json file looking like this:

"technicalHookName": {
    "type": "js",
    "name": "hookName",
    "path": "src/js-modules/yourModule.js",
    "channel": 0,
    "interval": 10000,
    "running": false
}
JavaScript hook module

The JavaScript module has access to the channel object of the discord.js wrapper. The code executed when the module is called belongs into the hook function.

module.exports = {
	hook: function(channel) {
		channel.send("This js message is automatically sent in a specific interval");
	}
};

The hook function is executed when the hooks.json has the an existing channel and is running.

Python hook module

The Python module has no access to the channel object, it receives no inputs. It just runs the python script and every call of print creates a bot message. It should look like this:

import sys

# insert code to handle the input parameters here

# This will be the msg that the bot sends
print("This py message is automatically sent in a specific interval")
sys.stdout.flush()  # cleanup
Lua hook module

The Lua module has also no access to the channel object, it receives no inputs. It just runs the lua script and every call of print creates a bot message. It should look like this:

-- Insert code here

-- This will be the msg that the bot sends
print("This lua message is automatically sent in a specific interval.")

This is again similar to Python modules.

Can I create pull request with new modules?

Yes, I will review your code and if it's good, I'll merge it into the master. Please adapt your code style regarding already existing modules.

Can I develop the bot without sharing my modules?

Yes, that's also ok. But it would be nice if more people could profit from your work.

dynobot's People

Contributors

blackhawk-ta avatar blackhawk312 avatar dependabot[bot] avatar isuraxi avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dynobot's Issues

How to fix this?

node main.js

node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module 'winston'
Require stack:

  • C:\Users\Администратор\Desktop\dynoBot-master\src\utils\logger.js
  • C:\Users\Администратор\Desktop\dynoBot-master\main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object. (C:\Users\Администратор\Desktop\dynoBot-master\src\utils\logger.js:1:44)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
    'C:\Users\Администратор\Desktop\dynoBot-master\src\utils\logger.js',
    'C:\Users\Администратор\Desktop\dynoBot-master\main.js'
    ]
    }

Node.js v17.1.0

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

@discordjs/opus error

Describe the bug
Unable to install all required dependencies due to errors with @discordjs.

See below:

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

@discordjs/[email protected] install /home/dynoBot/node_modules/@discordjs/opus
node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! install response status 404 Not Found on https://github.com/discordjs/opus/releases/download/v0.5.0/opus-v0.5.0-node-v64-napi-v3-linux-x64-glibc-2.28.tar.gz
node-pre-gyp WARN Pre-built binaries not installable for @discordjs/[email protected] and [email protected] (node-v64 ABI, glibc) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/discordjs/opus/releases/download/v0.5.0/opus-v0.5.0-node-v64-napi-v3-linux-x64-glibc-2.28.tar.gz
gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack at getNotFoundError (/usr/lib/node_modules/npm/node_modules/which/which.js:13:12)
gyp ERR! stack at F (/usr/lib/node_modules/npm/node_modules/which/which.js:68:19)
gyp ERR! stack at E (/usr/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/isexe/index.js:42:5
gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/isexe/mode.js:8:5
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:153:21)
gyp ERR! System Linux 4.18.0-240.22.1.el8_3.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/home/dynoBot/node_modules/@discordjs/opus/prebuild/node-v64-napi-v3-linux-x64-glibc-2.28/opus.node" "--module_name=opus" "--module_path=/home/dynoBot/node_modules/@discordjs/opus/prebuild/node-v64-napi-v3-linux-x64-glibc-2.28" "--napi_version=7" "--node_abi_napi=napi" "--napi_build_version=3" "--node_napi_label=napi-v3"
gyp ERR! cwd /home/dynoBot/node_modules/@discordjs/opus
gyp ERR! node -v v10.24.0
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/dynoBot/node_modules/@discordjs/opus/prebuild/node-v64-napi-v3-linux-x64-glibc-2.28/opus.node --module_name=opus --module_path=/home/dynoBot/node_modules/@discordjs/opus/prebuild/node-v64-napi-v3-linux-x64-glibc-2.28 --napi_version=7 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
node-pre-gyp ERR! stack at ChildProcess.cmd.on (/home/dynoBot/node_modules/@discordjs/node-pre-gyp/lib/util/compile.js:85:20)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:198:13)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:982:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
node-pre-gyp ERR! System Linux 4.18.0-240.22.1.el8_3.x86_64
node-pre-gyp ERR! command "/usr/bin/node" "/home/dynoBot/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/dynoBot/node_modules/@discordjs/opus
node-pre-gyp ERR! node -v v10.24.0
node-pre-gyp ERR! node-pre-gyp -v v0.3.2
node-pre-gyp ERR! not ok
Failed to execute '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/dynoBot/node_modules/@discordjs/opus/prebuild/node-v64-napi-v3-linux-x64-glibc-2.28/opus.node --module_name=opus --module_path=/home/dynoBot/node_modules/@discordjs/opus/prebuild/node-v64-napi-v3-linux-x64-glibc-2.28 --napi_version=7 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
npm WARN notsup Unsupported engine for @discordjs/[email protected]: wanted: {"node":">=12.0.0"} (current: {"node":"10.24.0","npm":"6.14.11"})
npm WARN notsup Not compatible with your version of node/npm: @discordjs/[email protected]

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @discordjs/[email protected] install: node-pre-gyp install --fallback-to-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @discordjs/[email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-06-21T11_07_50_219Z-debug.log

To Reproduce
Steps to reproduce the behavior:

  1. Clone the repository
  2. Run npm install in the repository directory
  3. See error

Expected behavior
I expect the dependencies to install without errors.

Screenshots
https://i.imgur.com/TcAwnqg.png

Additional context
To be fair, this could completely be user error - some assistance would be much appreciated.

Dependency removed?

When I run npm install, there is a dependency that doesn't exist anymore scrape-yt.

To Reproduce
Steps to reproduce the behavior:
clone and try npm install

Expected behavior
supposed to work and install dependency

Screenshots
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/scrape-yt/-/scrape-yt-1.3.1.tgz
npm ERR! 404
npm ERR! 404 '[email protected]' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'dynoBot'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/abs/.npm/_logs/2020-09-17T16_10_07_398Z-debug.log

Additional context
Add any other context about the problem here.

Voice Chat

Describe the bug
So basically, it wont work and it doesnt say how to make the bot join your vc.
When i do (@mention) addTitle (the song) it says "You can only get the current song when we are in the same voice channel."

image

Winston

I always get this error whenever I use node main.js

SyntaxError: C:\Users\clark\Programming\dynoBot-master\cfg\security.json: Unexpected token ` in JSON at position 0
at parse ()
at Object.Module._extensions..json (internal/modules/cjs/loader.js:1106:22)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object. (C:\Users\clark\Programming\dynoBot-master\src\utils\logger.js:4:18)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)

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.