Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions commands/handler/functions/pingPromoter.js

This file was deleted.

3 changes: 3 additions & 0 deletions commands/handler/initFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ module.exports = async () => {
const name = file.split('.')[0];

let func = require('./functions/' + file);
if (func[name] && func[name].active) {
func = func[name];
}

if (func.active) data.functions[name] = await func.init();

Expand Down
78 changes: 78 additions & 0 deletions src/commands/handler/functions/PingPromoter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Snowflake } from 'discord-api-types/v6';
import { Message, Role } from 'discord.js';

export class PingPromoter {

protected static readonly ROLE_ID: Snowflake = '1107382381700206672';
protected static readonly MONITORING_BOT_ID: Snowflake = '464272403766444044';
protected static readonly COMMAND: string = '</up:891377101494681660>';
protected static readonly TIMEOUT: number = 4 * 3600 * 1000;
protected static role: Role;

public static active: boolean = true;

public static title = {
ru: 'Автоматическое упоминание людей, готовых продвигать сервер',
en: 'Automatic mention of people who are ready to promote the server',
uk: 'Автоматичне згадування людей, що готові просувати сервер'
};

public static readonly allChannels: false;

public static readonly allowedChannels = {
'610371610620198922': false // #рандом
};

public static async init () {
// @ts-ignore TODO: ебучие глобал переменные
this.role = await guild.roles.fetch(this.ROLE_ID);
if (this.role === undefined) {
this.active = false;
}
return this;
}

public static async call (msg: Message) {
if (msg?.member?.user.id !== this.MONITORING_BOT_ID) return;

// @ts-ignore /functions/log.js
initLog(msg, 'pingPromoter');
// @ts-ignore
const log = msg.log;
// @ts-ignore /functions/sleep.js
const sleep = global.sleep;

let embed;
for (let i = 0; i < 5; i++) {
log('Fetch updated message. Try ' + i);

await sleep(1000);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тебя типо вообще ничего не смущает?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет


try {
const msgUpdated = await msg.channel.messages.fetch(msg.id);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ты понимаешь что этот ебейший костыль с циклом и слипом в нём сделан исключительно в надежде словить изменённое сообщение. Нужно переписать на client.on("message Update", message -> this.handle)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я уже пробовал это сделать.
Истина в том, что по какой то причине messageUpdate прилетает не тогда, когда появляется эмбед, а тогда, когда прилетает DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE.

Но ивенты не приходят от DEFERRED_UPDATE_MESSAGE.

Таким образом мы не можем с помощью messageUpdate получить момент, когда бот подсовывает эмбед.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ты уверен что именно ивент не прилетает, а не просто проверка какая то не прохоидт

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну через raw, справедливости ради, я не проверял. Но на raw я в целом переписывать не горю желанием. Пусть остаётся этот костыль

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да и это не костыль, нормальная логика


embed = msgUpdated.embeds[0];
} catch (e) {
log(e);
return;
}

if (embed) {
log('Embed found');
break;
}
}

if (!embed?.description?.includes('Успешный Up!')) {
log('Embed is invalid. Description: ' + embed?.description);
return;
}

log('Start sleep');
await sleep(this.TIMEOUT);
log('End sleep');

await msg.channel.send(this.role.toString() + ' ' + this.COMMAND);
}

}