-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from josephistired/v1.0.1-test
V1.0.1 release
- Loading branch information
Showing
7 changed files
with
669 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
.env | ||
.env | ||
commands/developer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,16 @@ | ||
# 🍾 Discord.js-Pi-hole-Bot | ||
This is a bot that utilizes the Pi-hole API to retrieve statistics and perform actions on your Pi-hole DNS server. With this bot, you can easily check the performance of your Pi-hole server and disable or enable it with simple commands, giving you full control over your network's DNS blocking capabilities. | ||
|
||
# 📊 Features | ||
- Simple commands | ||
- Easy to setup | ||
- And much more coming [soon](https://github.com/users/josephistired/projects/10) | ||
|
||
# 🔧 Prerequisites | ||
Before using this bot, you must have the latest version of node.js installed, an instance of Pi-hole running on a Raspberry Pi or your preferred device, your Pi-hole API token obtained from the Pi-hole dashboard, your Discord account ID and bot token, and the "Server Members Intent" and "Message Content Intent" enabled in your Discord developer portal, in addition to the "application.commands" scope enabled when inviting the bot to your server. | ||
# 📚 Wiki | ||
|
||
* [Node.js LTS](https://nodejs.org/en/) | ||
* [Pi-hole](https://docs.pi-hole.net/main/basic-install/) | ||
* [Pi-hole API Token](https://user-images.githubusercontent.com/65987360/215274165-f55ecf0c-f566-462d-bd4e-839d8416a5a4.png) | ||
| To obtain your Pi-hole API token, follow these steps: | ||
1. Log in to your Pi-hole Admin Console. | ||
2. Go to the Settings page, then the API/Web Interface tab. | ||
3. At the bottom of the page, click on the "Show API Token" button. | ||
4. Confirm the action in the pop-up window. | ||
5. A new window will appear with a QR code, copy the "Raw API Token" located below the QR code. | ||
6. Paste the copied token into the relevant configuration file for this bot. | ||
* [Discord Account ID](https://www.businessinsider.com/guides/tech/discord-id) | ||
* [Discord Bot Token](https://discord.com/developers/applications) | ||
* [Server Members Intent and Message Content Intent Enabled](https://autocode.com/discord/threads/what-are-discord-privileged-intents-and-how-do-i-enable-them-tutorial-0c3f9977/) | ||
* [Application.commands Checked](https://user-images.githubusercontent.com/65987360/215274052-ea7c0c8d-505d-43f8-b16a-1673bdffe032.png) | ||
To learn how to use this bot, go to the [wiki](https://www.josephcarmosino.website/discordpiholebot#wiki). Also to view the commands for this bot. | ||
|
||
# 💫 Getting Started | ||
Now that you have all the required Prerequisites. You can move on to the next steps. By running the commands below. | ||
|
||
``` | ||
git clone https://github.com/josephistired/Discord-Pi-hole-Bot.git | ||
cd Discord-Pi-hole-Bot | ||
npm install | ||
``` | ||
|
||
# ⚙️ Configuration | ||
Once you have cloned the bot to your local machine and have all the necessary prerequisites in place, you must now edit the configuration file for the bot to properly use the Pi-hole API. Before, you do anything remove the ".example" part of the .env file, so that it is just named ".env" without the file extension. | ||
|
||
Enter your Discord Bot Token, Auth for Pi-hole, Discord Account ID, and the IP of your Pi-hole. | ||
|
||
``` | ||
TOKEN= Discord Bot Token Here | ||
AUTH= Pi-hole Auth Token Here | ||
ID= Discord Account ID Here | ||
IP= IP of Pi-hole Here | ||
``` | ||
|
||
Crtl - S | ||
|
||
# 🎊 Starting The Bot | ||
|
||
If you have successfully completed all the previous steps, the bot should now be ready to run. If you are on Windows, you can run the bot by opening the bot.bat file. Once the bot is running, you can enjoy its features! If you encounter any issues, you can create a pull request for help. | ||
|
||
|
||
# 💬 Commands | ||
|
||
With this bot, you can use the following commands: | ||
|
||
* /pihole view: Allows you to view statistics about your Pi-hole server, such as the number of domains being blocked, number of DNS queries to date, percentage of queries blocked, number of cached queries, number of clients, privacy level, and last gravity update. | ||
* /pihole disable [seconds]: Allows you to disable your Pi-hole server for an indefinite period of time or for a specified number of seconds. | ||
* /pihole enable: Allows you to re-enable your Pi-hole server after it has been disabled. | ||
|
||
# 🤚🏻 Disclaimer | ||
|
||
**Please note that this bot is not endorsed, sponsored by, or associated with Pi-hole. It is an independent project that uses the Pi-hole API, but is not endorsed or supported by the Pi-hole team. This bot is not affiliated with the Pi-hole developers or their respective trademarks. Use this bot at your own risk and always make sure to read the documentation and understand how it works before using it.** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
const { ChatInputCommandInteraction, EmbedBuilder } = require("discord.js"); | ||
const superagent = require("superagent"); | ||
require("dotenv").config(); | ||
|
||
module.exports = { | ||
subCommand: "pihole.queries", | ||
/** | ||
* @param {ChatInputCommandInteraction} interaction | ||
*/ | ||
async execute(interaction) { | ||
let { body } = await superagent.get( | ||
`${process.env.IP}/admin/api.php?summaryRaw&auth=${process.env.AUTH}` | ||
); | ||
|
||
const chart = { | ||
type: "bar", | ||
data: { | ||
datasets: [ | ||
{ | ||
fill: true, | ||
spanGaps: false, | ||
lineTension: 0.4, | ||
pointRadius: 3, | ||
pointHoverRadius: 3, | ||
pointStyle: "circle", | ||
borderDash: [0, 0], | ||
barPercentage: 0.9, | ||
categoryPercentage: 0.8, | ||
data: [ | ||
body.reply_UNKNOWN, | ||
body.reply_NODATA, | ||
body.reply_NXDOMAIN, | ||
body.reply_CNAME, | ||
body.reply_IP, | ||
body.reply_DOMAIN, | ||
body.reply_RRNAME, | ||
body.reply_SERVFAIL, | ||
body.reply_REFUSED, | ||
body.reply_NOTIMP, | ||
body.reply_OTHER, | ||
body.reply_DNSSEC, | ||
body.reply_NONE, | ||
body.reply_BLOB, | ||
], | ||
type: "bar", | ||
label: "Type of Queries", | ||
borderColor: "#f20900", | ||
backgroundColor: "#4E79A733", | ||
borderWidth: 3, | ||
hidden: false, | ||
}, | ||
], | ||
labels: [ | ||
"UNKNOWN", | ||
"NODATA", | ||
"NXDOMAIN", | ||
"CNAME", | ||
"IP", | ||
"DOMAIN", | ||
"RRNAME", | ||
"SERVFAIL", | ||
"REFUSED", | ||
"NOTIMP", | ||
"OTHER", | ||
"DNSSEC", | ||
"NONE", | ||
"BLOB", | ||
], | ||
}, | ||
options: { | ||
title: { | ||
display: false, | ||
position: "top", | ||
fontSize: 12, | ||
fontFamily: "sans-serif", | ||
fontColor: "#666666", | ||
fontStyle: "bold", | ||
padding: 10, | ||
lineHeight: 1.2, | ||
text: "Chart title", | ||
}, | ||
layout: { | ||
padding: { | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
bottom: 0, | ||
}, | ||
}, | ||
plugins: { | ||
datalabels: { | ||
display: true, | ||
align: "center", | ||
anchor: "center", | ||
backgroundColor: "#eee", | ||
borderColor: "#ddd", | ||
borderRadius: 6, | ||
borderWidth: 1, | ||
padding: 4, | ||
color: "#000000", | ||
font: { | ||
family: "sans-serif", | ||
size: 8, | ||
style: "normal", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const encodedChart = encodeURIComponent(JSON.stringify(chart)); | ||
const chartUrl = `https://quickchart.io/chart?c=${encodedChart}`; | ||
|
||
const stats = new EmbedBuilder().setImage(chartUrl); | ||
|
||
interaction.reply({ embeds: [stats] }); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.