-
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.
feat: add support for kicking members from servers
partial fix for #1 (no support for groups yet)
- Loading branch information
Showing
4 changed files
with
147 additions
and
5 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { sendMsg } from "./send.js"; | ||
export { kick } from "./kick.js"; | ||
export { default as styles } from "./styles.js"; |
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,105 @@ | ||
import { Client } from "revolt.js"; | ||
|
||
import styles from "./styles.js"; | ||
|
||
const kick = function (userType, token, server, userid) { | ||
// if any args are missing, throw errors before doing anything | ||
if (!userType) | ||
return ( | ||
console.log( | ||
styles.error( | ||
"You need to specify if the account is a user or a bot (--user or --bot), a token, a server ID and the ID of the user to kick (all in quotes)." | ||
) | ||
) && process.exit() | ||
); | ||
if (!token) | ||
return ( | ||
console.log( | ||
styles.error( | ||
"You need to specify a token, a server ID and the ID of the user to kick (the last two in quotes)." | ||
) | ||
) && process.exit() | ||
); | ||
if (!server) | ||
return ( | ||
console.log( | ||
styles.error( | ||
"You need to specify a server ID and the ID of the user to kick (both in quotes)." | ||
) | ||
) && process.exit() | ||
); | ||
if (!userid) | ||
return ( | ||
console.log( | ||
styles.error( | ||
"You need to specify the content of the message (in quotes)." | ||
) | ||
) && process.exit() | ||
); | ||
|
||
// check and get user type | ||
const checkIfUser = function (type) { | ||
switch (type) { | ||
case "--user": | ||
return true; | ||
case "--bot": | ||
return false; | ||
default: | ||
return "invalid"; | ||
} | ||
}; | ||
const isUser = checkIfUser(userType); | ||
if (isUser === "invalid") | ||
console.log( | ||
styles.error( | ||
"The user type was invalid - make sure to specify if you're using a seisson token (--user) or a bot token (--bot)." | ||
) | ||
); | ||
|
||
// log in | ||
const client = new Client(); | ||
try { | ||
isUser ? client.useExistingSession(token) : client.loginBot(token); | ||
console.log(styles.info("[INFO] Logged in.")); | ||
} catch (error) { | ||
console.log( | ||
styles.error( | ||
`There was an issue logging in - are your token and user type correct?\nThe issue was: ${error}` | ||
) | ||
); | ||
} | ||
|
||
client.on("ready", async () => { | ||
try { | ||
const srv = client.servers?.get(server); | ||
if (srv === undefined) throw error; | ||
} catch (error) { | ||
console.log( | ||
styles.error( | ||
`There was an issue getting the server - is the ID correct?\nThe error was: ${error}` | ||
) | ||
) && client.logout(); | ||
process.exit(); | ||
} | ||
|
||
const server2 = client.servers?.get(server); | ||
console.log(styles.info("[INFO] The server has been found.")); | ||
|
||
// send the message | ||
try { | ||
await (await server2.fetchMember(userid)).kick(); | ||
console.log(styles.success("The user has been kicked.")); | ||
} catch (error) { | ||
console.log( | ||
styles.error( | ||
`There was an issue sending the message.\n\nThe error was: ${error}` | ||
) | ||
); | ||
} | ||
|
||
// for SOME reason we need to end the process manually after sending the message - is something lingering? | ||
process.kill(process.pid); | ||
}); | ||
}; | ||
|
||
export { kick }; |