-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor handler #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Refactor handler #86
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| 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); | ||
|
|
||
| try { | ||
| const msgUpdated = await msg.channel.messages.fetch(msg.id); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ты понимаешь что этот ебейший костыль с циклом и слипом в нём сделан исключительно в надежде словить изменённое сообщение. Нужно переписать на
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я уже пробовал это сделать. Но ивенты не приходят от DEFERRED_UPDATE_MESSAGE. Таким образом мы не можем с помощью messageUpdate получить момент, когда бот подсовывает эмбед.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ты уверен что именно ивент не прилетает, а не просто проверка какая то не прохоидт
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ну через
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тебя типо вообще ничего не смущает?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нет