-
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.
2/5 for #1
- Loading branch information
Showing
6 changed files
with
139 additions
and
8 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,106 @@ | ||
import { Client } from "revolt.js"; | ||
|
||
import styles from "./styles.js"; | ||
|
||
const ban = 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 ban (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 ban (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 ban (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 { | ||
const reason = undefined; // todo: add reason support | ||
await server2.banUser(userid, { reason }); | ||
console.log(styles.success("The user has been banned.")); | ||
} catch (error) { | ||
console.log( | ||
styles.error( | ||
`There was an issue banning the user.\n\nThe error was: ${error}` | ||
) | ||
); | ||
} | ||
|
||
// for SOME reason we need to end the process manually after banning the user - is something lingering? | ||
process.kill(process.pid); | ||
}); | ||
}; | ||
|
||
export { ban }; |
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,3 +1,4 @@ | ||
export { sendMsg } from "./send.js"; | ||
export { kick } from "./kick.js"; | ||
export { ban } from "./ban.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
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