Skip to content

Commit

Permalink
upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ender-null committed Mar 30, 2024
1 parent 28939e7 commit 807476f
Show file tree
Hide file tree
Showing 15 changed files with 2,747 additions and 2,241 deletions.
60 changes: 30 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polaris",
"version": "0.9.16",
"version": "0.10.1",
"description": "A multi platform TypeScript bot using plugins!",
"license": "AGPL-3.0",
"author": {
Expand Down Expand Up @@ -39,44 +39,44 @@
},
"dependencies": {
"cheerio": "^1.0.0-rc.12",
"discord.js": "^13.6.0",
"firebase": "^9.22.0",
"discord.js": "^14.14.1",
"firebase": "^10.10.0",
"form-data": "^4.0.0",
"html-to-text": "^8.1.0",
"matrix-bot-sdk": "^0.6.6",
"mime-types": "^2.1.30",
"node-cron": "^3.0.0",
"node-fetch": "^2.6.7",
"prebuilt-tdlib": "td-1.8.12",
"html-to-text": "^9.0.5",
"matrix-bot-sdk": "^0.7.1",
"mime-types": "^2.1.35",
"node-cron": "^3.0.3",
"node-fetch": "^2",
"prebuilt-tdlib": "^0.1008026.0",
"string-format": "^2.0.0",
"tdl": "v7.2.0",
"tdl": "v7.4.1",
"tdl-tdlib-addon": "^1.2.2",
"tmp": "^0.2.1",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.6.0"
"tmp": "^0.2.3",
"winston": "^3.13.0",
"winston-daily-rotate-file": "^5.0.0"
},
"devDependencies": {
"@types/mime-types": "^2.1.0",
"@types/node": "^17.0.10",
"@types/mime-types": "^2.1.4",
"@types/node": "^20.12.2",
"@types/node-fetch": "^3.0.3",
"@types/tmp": "^0.2.0",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"eslint": "^8.7.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.2",
"@types/tmp": "^0.2.6",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-config-standard-with-typescript": "^21.0.1",
"eslint-plugin-ava": "^13.2.0",
"eslint-plugin-import": "^2.23.3",
"eslint-plugin-ava": "^14.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.1.1",
"fluture": "^14.0.0",
"husky": "^7.0.4",
"prettier": "^2.3.0",
"tdlib-types": "td-1.8.12",
"typedoc": "^0.22.11",
"typescript": "^4.5.5"
"husky": "^9.0.11",
"prettier": "^3.2.5",
"tdlib-types": "td-1.8.14",
"typedoc": "^0.25.12",
"typescript": "^5.4.3"
},
"keywords": [
"polaris",
Expand Down
75 changes: 61 additions & 14 deletions src/bindings/discord.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import { Client, Message as DiscordMessage, MessageAttachment, MessageEmbed } from 'discord.js';
import {
ActivityType,
AttachmentBuilder,
CacheType,
ChatInputCommandInteraction,
Client,
Message as DiscordMessage,
EmbedBuilder,
GatewayIntentBits,
Interaction,
Partials,
} from 'discord.js';
import { BindingsBase, Bot, Conversation, ConversationInfo, Extra, Message, User } from '..';
import { db } from '../main';
import { getExtension, htmlToDiscordMarkdown, linkRegExp, logger, splitLargeMessage } from '../utils';
import { htmlToDiscordMarkdown, linkRegExp, logger, splitLargeMessage } from '../utils';

export class DiscordBindings extends BindingsBase {
client: Client;
pendingMessages: { msg: Message; message: DiscordMessage }[];
constructor(bot: Bot) {
super(bot);
this.client = new Client({
restRequestTimeout: 60000,
intents: 0,
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
],
partials: [Partials.Message, Partials.Channel],
});
}

Expand All @@ -28,13 +48,15 @@ export class DiscordBindings extends BindingsBase {
activities: [
{
name: `${this.bot.config.prefix}help`,
type: 'LISTENING',
type: ActivityType.Listening,
},
],
});
this.bot.status.emit('started');
});

this.client.on('interactionCreate', (interaction: Interaction<CacheType>) =>
this.interactionEventHandler(interaction),
);
this.client.on('messageCreate', (message: DiscordMessage) => this.messageEventHandler(message));
this.client.login(this.bot.config.apiKeys.discordBotToken).then(
(tok) => {
Expand Down Expand Up @@ -97,6 +119,32 @@ export class DiscordBindings extends BindingsBase {
return new Message(id, conversation, sender, content, type, date, reply, extra);
}

async convertInteraction(msg: ChatInputCommandInteraction<CacheType>): Promise<Message> {
const id = msg.id;
const extra: Extra = {
originalMessage: msg,
};
const content = msg.commandName;
const type = 'text';
const date = msg.createdTimestamp;
const reply = null;
const sender = new User(msg.user.id, msg.user.username, `#${msg.user.discriminator}`, msg.user.tag, msg.user.bot);
const conversation = new Conversation('-' + msg.channel.id);
const channel = await this.client.channels.fetch(msg.channel.id);
if (channel.constructor.name == 'DMChannel') {
conversation.id = channel['recipient']['id'];
conversation.title = channel['recipient']['username'];
} else {
conversation.title = channel['name'];
}
return new Message(id, conversation, sender, content, type, date, reply, extra);
}

async interactionEventHandler(interaction: Interaction<CacheType>): Promise<void> {
if (!interaction.isChatInputCommand()) return;
this.bot.inbox.emit('message', await this.convertInteraction(interaction));
}

async messageEventHandler(message: DiscordMessage): Promise<void> {
// // don't respond to ourselves
if (+message.author.id == this.bot.user.id) {
Expand Down Expand Up @@ -147,28 +195,27 @@ export class DiscordBindings extends BindingsBase {
}
} else if (msg.type == 'photo' || msg.type == 'document' || msg.type == 'video' || msg.type == 'voice') {
let sendContent = true;
const embed = new MessageEmbed();
const embed = new EmbedBuilder();

if (msg.extra && 'caption' in msg.extra && msg.extra['caption']) {
const lines = msg.extra['caption'].split('\n');
embed.title = lines[0];
embed.setTitle(lines[0]);
lines.splice(0, 1);
embed.description = lines.join('\n');
embed.setDescription(lines.join('\n'));
sendContent = false;
}

if (sendContent) {
if (msg.content.startsWith('/') || msg.content.startsWith('C:\\')) {
await chat.send(new MessageAttachment(msg.content, msg.type + getExtension(msg.content)));
const file = new AttachmentBuilder(msg.content);
await chat.send({ files: [file] });
} else {
await chat.send(msg.content);
}
} else {
if (msg.content.startsWith('/') || msg.content.startsWith('C:\\')) {
await chat.send({
embeds: [embed],
files: [new MessageAttachment(msg.content, msg.type + getExtension(msg.content))],
});
const file = new AttachmentBuilder(msg.content);
await chat.send({ embeds: [embed], files: [file] });
} else if (msg.content.startsWith('http')) {
if (msg.type == 'photo') {
embed.setImage(msg.content);
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class MatrixBindings extends BindingsBase {
const joinedRooms = await this.client.getJoinedRooms();
await this.client.crypto.prepare(joinedRooms); // init crypto because we're doing things before the client is started
AutojoinRoomsMixin.setupOnClient(this.client);
this.client.setPresenceStatus("online", `Listening to ${this.bot.config.prefix}help`)
this.client.setPresenceStatus('online', `Listening to ${this.bot.config.prefix}help`);
this.client.on('room.message', (roomId: string, event) => this.eventHandler(roomId, event));
this.bot.outbox.on('message', (msg: Message) => this.sendMessage(msg));
this.client.start().then(() => this.bot.status.emit('started'));
Expand Down Expand Up @@ -156,7 +156,7 @@ export class MatrixBindings extends BindingsBase {
}

async stop(): Promise<void> {
this.client.setPresenceStatus("offline")
this.client.setPresenceStatus('offline');
this.client.removeAllListeners('room.message');
this.bot.outbox.removeAllListeners('message');
this.bot.status.emit('stopped');
Expand Down
Loading

0 comments on commit 807476f

Please sign in to comment.