Skip to content

Commit

Permalink
refactor and some bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ender-null committed May 25, 2024
1 parent a5cc7e8 commit bfafad0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export class Bot {
this.send(message).then();
});
} else {
const message = new Message(null, chat, this.user, content, type, now(), reply, extra);
const message = new Message(null, chat, this.user, content.trim(), type, now(), reply, extra);
this.send(message).then();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/reddit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class RedditPlugin extends PluginBase {
super(bot);
this.commands = [
{
friendly: 'r',
friendly: 'r/',
description: 'Links to subreddit',
hidden: true,
},
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/world-of-warcraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class WorldOfWarcraftPlugin extends PluginBase {
if (!this.accessToken) {
this.accessToken = await this.retrievingAccessToken();
}
const input = getInput(msg, false);
const input = getInput(msg);
let text = '';
const uid = String(msg.sender.id);

Expand Down Expand Up @@ -137,6 +137,9 @@ export class WorldOfWarcraftPlugin extends PluginBase {
);
this.bot.replyMessage(msg, wowset);
}
if (!realm.length || !characterName.length) {
return this.bot.replyMessage(msg, this.bot.errors.missingParameter);
}
const [character, media, raids, pvp, professions, statistics, raiderIO] = await Promise.all([
this.getCharacter(region, realm, characterName),
this.getCharacterMedia(region, realm, characterName),
Expand Down
13 changes: 5 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,10 @@ export const setInput = (message: Message, trigger: string): Message => {
if (message.type == 'text') {
trigger = trigger.replace('$', '');
// Get the text that is next to the pattern
const inputMatch = new RegExp(`${trigger}(.+)$`, 'gim').exec(message.content);
const regex = new RegExp(`${trigger}(.+)$`, 'gim');
const inputMatch = regex.exec(message.content);
if (inputMatch && inputMatch.length > 0 && inputMatch[1]) {
if (inputMatch[1].startsWith(' ')) {
message.extra.input = inputMatch[1].slice(1);
} else {
message.extra.input = inputMatch[1];
}
message.extra.input = inputMatch[1].trim();
}

// Get the text that is next to the pattern
Expand All @@ -433,9 +430,9 @@ export const setInput = (message: Message, trigger: string): Message => {

export const getInput = (message: Message, ignoreReply = true): string => {
if (Object.keys(message.extra).length > 0) {
if (ignoreReply && 'input' in message.extra) {
if (ignoreReply && message.extra.input) {
return message.extra.input;
} else if (!ignoreReply && 'inputReply' in message.extra) {
} else if (!ignoreReply && message.extra.inputReply) {
return message.extra.inputReply;
}
}
Expand Down

0 comments on commit bfafad0

Please sign in to comment.