mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 23:22:56 +00:00
feat: nextdns features
This commit is contained in:
parent
bf922fae42
commit
60eae376bd
2 changed files with 66 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import { getJellyfinStatus, getSpotifyStatus } from "./modules/status";
|
|||
import { getResponse } from "./modules/randomResponseSystem";
|
||||
import * as utils from "./modules/index";
|
||||
import howWasYourDay from "./modules/howWasYourDay";
|
||||
import { myPrivateDNS } from "./modules/nextdns";
|
||||
|
||||
const db = new JSONdb("data.json");
|
||||
app.start(process.env.PORT || 3000).then(async (d) => {
|
||||
|
|
@ -25,6 +26,7 @@ app.start(process.env.PORT || 3000).then(async (d) => {
|
|||
text: `Starting Slack Bot :D`,
|
||||
});
|
||||
init(app);
|
||||
myPrivateDNS(app);
|
||||
});
|
||||
// app.client.cha
|
||||
const cmdLoader = new Loader(app, path.join(__dirname, "commands"));
|
||||
|
|
|
|||
64
src/modules/nextdns.ts
Normal file
64
src/modules/nextdns.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import { ModifiedApp } from "./slackapp"
|
||||
|
||||
export interface Root {
|
||||
timestamp: string
|
||||
domain: string
|
||||
root: string
|
||||
encrypted: boolean
|
||||
protocol: string
|
||||
clientIp: string
|
||||
device: Device
|
||||
status: string
|
||||
reasons: Reason[]
|
||||
}
|
||||
|
||||
export interface Reason {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
export interface Device {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export function myPrivateDNS(app: ModifiedApp) {
|
||||
fetch(`https://api.nextdns.io/profiles/${process.env.MY_NEXTDNS}/logs/stream`,
|
||||
{ headers:
|
||||
{ "X-Api-Key": process.env.NEXTDNS_API_KEY }}
|
||||
).then(r=>{
|
||||
const reader = r.body?.getReader();
|
||||
const rs = require("stream").Readable();
|
||||
rs._read = async () => {
|
||||
const result = await reader?.read();
|
||||
if(!result?.done){
|
||||
//@ts-ignore
|
||||
rs.push(Buffer.from(result.value));
|
||||
}else{
|
||||
rs.push(null);
|
||||
return;
|
||||
}
|
||||
};
|
||||
//@ts-ignore
|
||||
rs.on('data', (d) => {
|
||||
const str = d.toString()
|
||||
if(str.includes(':keepalive')) return;
|
||||
console.debug(str)
|
||||
let splits = str.split('\n')
|
||||
let id = splits[0].split(/ +/)[1]
|
||||
let data = splits[1].split(":").slice(1).join(":")
|
||||
if(!id || !data) return;
|
||||
const realData:Root = JSON.parse(data)
|
||||
console.log(realData)
|
||||
//@ts-ignore
|
||||
delete realData.clientIp;
|
||||
// console.log(`${realData.status == 'blocked' ? ':x:' : ":white_check_mark:"} ${realData.encrypted ? ":lock: " : ""} - ${realData.domain} `)
|
||||
app.client.chat.postMessage({
|
||||
channel: `C07LT7XS28Z`,
|
||||
text: `${realData.status == 'blocked' ? ':x:' : ":white_check_mark:"} ${realData.encrypted ? ":lock: " : ""} - ${realData.domain} `,
|
||||
});
|
||||
})
|
||||
rs.on('end', () => {
|
||||
console.log('end')
|
||||
})
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue