Compare commits
1 Commits
8d340db915
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d3cbd29482 |
1
index.js
1
index.js
@@ -80,6 +80,7 @@ client.on(Events.MessageCreate, message => {
|
||||
if (regexProfile) {
|
||||
const cocklink = convertURL(regexProfile[0], twitterRegex, "girlcockx.com")
|
||||
message.channel.send({ content: cocklink, flags: MessageFlags.SuppressNotifications, components: [swapRow] })
|
||||
.catch(err => console.error("Failed to send converted link: " + (err.message || err)))
|
||||
message.suppressEmbeds().catch(err =>
|
||||
// this next bit just cuts down the error to the important part, which will usually end up being "no permissions"
|
||||
console.error("Removing original embed failed: " + err.stack?.split('\n')[0] || err.message || String(err).split('\n')[0])
|
||||
|
||||
@@ -5,7 +5,6 @@ const config = require('../config.json');
|
||||
const AVATAR_DIR = path.join(__dirname, '../avatars');
|
||||
let avatarFiles = [];
|
||||
let currentAvatarIndex = 0;
|
||||
let timer = null;
|
||||
|
||||
function loadAvatars() {
|
||||
try {
|
||||
@@ -31,17 +30,19 @@ function loadAvatars() {
|
||||
}
|
||||
}
|
||||
|
||||
function rotateAvatar(client) {
|
||||
async function rotateAvatar(client) {
|
||||
if (avatarFiles.length === 0) return;
|
||||
|
||||
const avatarFile = avatarFiles[currentAvatarIndex];
|
||||
const avatarPath = path.join(AVATAR_DIR, avatarFile);
|
||||
|
||||
try {
|
||||
client.user.setAvatar(avatarPath);
|
||||
await client.user.setAvatar(avatarPath);
|
||||
console.log(`Avatars: Changed avatar to ${avatarFile}`);
|
||||
} catch (err) {
|
||||
console.error(`Avatars: Failed to set avatar to ${avatarFile}:`, err);
|
||||
console.error(`Avatars: Failed to set avatar to ${avatarFile}:`, err.message || err);
|
||||
} finally { // discordjs is evil and deletes the token every time the avatar changes
|
||||
client.rest.setToken(config.token);
|
||||
}
|
||||
|
||||
currentAvatarIndex = (currentAvatarIndex + 1) % avatarFiles.length;
|
||||
@@ -50,7 +51,6 @@ function rotateAvatar(client) {
|
||||
function init(client) {
|
||||
loadAvatars();
|
||||
|
||||
// Watch for changes in the avatars directory
|
||||
let fsWait = null;
|
||||
fs.watch(AVATAR_DIR, (eventType, filename) => {
|
||||
if (filename) {
|
||||
@@ -67,11 +67,8 @@ function init(client) {
|
||||
|
||||
console.log(`Avatars: Starting avatar rotation every ${intervalMinutes} minutes`);
|
||||
|
||||
// Initial rotation
|
||||
rotateAvatar(client);
|
||||
|
||||
// make it wait every interval before rotating
|
||||
timer = setInterval(() => rotateAvatar(client), intervalMs);
|
||||
setInterval(() => rotateAvatar(client), intervalMs);
|
||||
}
|
||||
|
||||
module.exports = { init };
|
||||
|
||||
Reference in New Issue
Block a user