-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added afk feature
!afk [on off status]
- Loading branch information
Showing
8 changed files
with
1,921 additions
and
10 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
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,56 @@ | ||
const { startAfk, afkStatus, stopAfk } = require("../helpers/afkWrapper"); | ||
|
||
const execute = async (client, msg, args) => { | ||
msg.delete(true); | ||
try { | ||
let commandType = args.shift(); | ||
|
||
switch (commandType) { | ||
case "on": { | ||
let getstatus = afkStatus(); | ||
if (getstatus.on) throw new Error("Already AFK mode is on."); | ||
let message = args.join(" "); | ||
if (!message) message = "Currently I'm away. I will be back soon!"; | ||
startAfk(message); | ||
let msgtosend = `AFK mode is now on.\n\nMessage: ${message}`; | ||
await client.sendMessage(msg.to, msgtosend); | ||
break; | ||
} | ||
case "off": { | ||
let getstatus = afkStatus(); | ||
if (!getstatus.on) throw new Error("Already AFK mode is off."); | ||
stopAfk(); | ||
let msgtosend = "AFK mode is now off."; | ||
await client.sendMessage(msg.to, msgtosend); | ||
break; | ||
} | ||
case "status": { | ||
let getstatus = afkStatus(); | ||
let msgtosend = `AFK mode is ${getstatus.on ? "on" : "off"}.${ | ||
getstatus.on ? `\n\nMessage: ${getstatus.message}` : "" | ||
}`; | ||
|
||
await client.sendMessage(msg.to, msgtosend); | ||
break; | ||
} | ||
default: { | ||
throw new Error( | ||
"Invalid argument. Valid arguments are: on, off, status" | ||
); | ||
} | ||
} | ||
} catch (error) { | ||
let messagetosend = `Afk command failed.\n\n${error?.message}`; | ||
await client.sendMessage(msg.to, messagetosend); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
name: "afk", //name of the module | ||
description: "Turn on or off afk mode", // short description of what this command does | ||
command: "!afk", //command with prefix. Ex command: '!test' | ||
commandType: "admin", // admin|info|plugin | ||
isDependent: false, //whether this command is related/dependent to some other command | ||
help: "*Afk*\n\n1. *!afk on Message* to turn on afk.\n2. *!afk off* to turn off afk.\n3. *!afk status* to check current status of afk.", // a string descring how to use this command Ex = help : 'To use this command type !test arguments' | ||
execute, | ||
}; |
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,6 +1,6 @@ | ||
SESSION_KEY="tuhin" | ||
PMPERMIT_ENABLED = 'true' | ||
MONGODB_URL = '' | ||
DEFAULT_TR_LANG = 'en' | ||
ENABLE_DELETE_ALERT = 'true' | ||
OCR_SPACE_API_KEY = '' | ||
SESSION_KEY="" | ||
PMPERMIT_ENABLED="true" | ||
MONGODB_URL="mongodb://tuhin:tuhin@localhost:27017/" | ||
DEFAULT_TR_LANG="en" | ||
ENABLE_DELETE_ALERT="true" | ||
OCR_SPACE_API_KEY="" |
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,41 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
function startAfk(message) { | ||
fs.writeFileSync( | ||
path.join(__dirname, `../cache/afk.json`), | ||
JSON.stringify({ | ||
on: true, | ||
message: message || "Currently I'm away. I will be back soon!", | ||
}) | ||
); | ||
} | ||
|
||
function afkStatus() { | ||
try { | ||
return JSON.parse( | ||
fs.readFileSync(path.join(__dirname, `../cache/afk.json`)) | ||
); | ||
} catch (error) { | ||
return { | ||
on: false, | ||
message: null, | ||
}; | ||
} | ||
} | ||
|
||
function stopAfk() { | ||
fs.writeFileSync( | ||
path.join(__dirname, `../cache/afk.json`), | ||
JSON.stringify({ | ||
on: false, | ||
message: null, | ||
}) | ||
); | ||
} | ||
|
||
module.exports = { | ||
startAfk, | ||
afkStatus, | ||
stopAfk, | ||
}; |
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
Oops, something went wrong.