Skip to content

Commit

Permalink
feat(commands): Add chat commands
Browse files Browse the repository at this point in the history
  • Loading branch information
skarab42 committed Jan 22, 2021
1 parent 452287d commit 65e28cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/server/libs/twitch/chat/onCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ module.exports = async function onCommand({ channel, command, nick, message }) {
command.args.push(rest.join(" "));
}

let chatMessage = (commandEntry.message || "").trim();

argNames.forEach((arg, i) => {
args[arg] = command.args[i] || `$${arg}`;
chatMessage = chatMessage.replaceAll(`$${arg}`, args[arg]);
});

cooldowns[command.name] = now;
pushActions("onCommand", { user: nick, message, command, ...args });

if (chatMessage.length) {
this.say(channel, chatMessage);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export let command;
function update(key, { target }) {
command[key] = target.value;
command[key] = target.value.trim();
api.updateCommand(command);
}
</script>
Expand All @@ -22,7 +22,7 @@
on:change="{update.bind(null, 'name')}"
/>
<Input
label="{_('words.usage')}"
label="{_('words.variables')}"
value="{command.usage}"
on:change="{update.bind(null, 'usage')}"
/>
Expand All @@ -38,6 +38,14 @@
value="{command.cooldown}"
on:change="{update.bind(null, 'cooldown')}"
/>
<div class="p-2 text-gray-700 uppercase text-xl font-bold">
{_('words.message')}
</div>
<textarea
class="p-2 text-dark"
on:change="{update.bind(null, 'message')}"
style="min-width:50vw; min-height:250px"
>{command.message}</textarea>
</div>
</div>
</Modal>

0 comments on commit 65e28cb

Please sign in to comment.