mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
reworked !use and !info, moved functionality from timeout to item
This commit is contained in:
@@ -2,9 +2,9 @@ import { Command, sendMessage } from ".";
|
|||||||
import items from "../items";
|
import items from "../items";
|
||||||
|
|
||||||
export default new Command('iteminfo', ['iteminfo', 'itemhelp', 'info'], [], async msg => {
|
export default new Command('iteminfo', ['iteminfo', 'itemhelp', 'info'], [], async msg => {
|
||||||
const messageparts = msg.messageText.split(' ');
|
const messagequery = msg.messageText.trim().split(' ').slice(1).join(' ');
|
||||||
if (!messageparts[1]) { await sendMessage('Please specify an item you would like to get info about', msg.messageId); return; };
|
if (!messagequery) { await sendMessage('Please specify an item you would like to get info about', msg.messageId); return; };
|
||||||
const selection = items.get(messageparts[1].toLowerCase());
|
const selection = items.get(messagequery.toLowerCase());
|
||||||
if (!selection) { await sendMessage(`'${messageparts[1]}' is not an item`, msg.messageId); return; };
|
if (!selection) { await sendMessage(`'${messagequery}' is not an item`, msg.messageId); return; };
|
||||||
await sendMessage(`Name: ${selection.prettyName}, Description: ${selection.description}, Aliases: ${selection.aliases.join(', ')}`, msg.messageId);
|
await sendMessage(`Name: ${selection.prettyName}, Description: ${selection.description}, Aliases: ${selection.aliases.join(', ')}`, msg.messageId);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import { Command, sendMessage } from ".";
|
|||||||
import items from "../items";
|
import items from "../items";
|
||||||
|
|
||||||
export default new Command('use', ['use'], [], async (msg, user) => {
|
export default new Command('use', ['use'], [], async (msg, user) => {
|
||||||
const messageparts = msg.messageText.split(' ');
|
const messagequery = msg.messageText.trim().split(' ').slice(1);
|
||||||
if (!messageparts[1]) { await sendMessage('Please specify an item you would like to use', msg.messageId); return; };
|
if (!messagequery[0]) { await sendMessage('Please specify an item you would like to use', msg.messageId); return; };
|
||||||
const selection = items.get(messageparts[1].toLowerCase());
|
const selection = items.get(messagequery[0].toLowerCase());
|
||||||
if (!selection) { await sendMessage(`'${messageparts[1]}' is not an item`, msg.messageId); return; };
|
if (!selection) { await sendMessage(`'${messagequery[0]}' is not an item`, msg.messageId); return; };
|
||||||
await selection.execute(msg, user);
|
await selection.execute(msg, user);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ eventSub.onChannelChatMessage(streamerId, streamerId, async msg => {
|
|||||||
// Given the fact that this is the user that chats, this user object always exists and cannot be null
|
// Given the fact that this is the user that chats, this user object always exists and cannot be null
|
||||||
//
|
//
|
||||||
// One of the flaws with the user object is solved by creating the object with the name.
|
// One of the flaws with the user object is solved by creating the object with the name.
|
||||||
// This way, if a user changes their name, the original name stays in the cache for at least 1 hour (extendable by using that name to timeout)
|
// This way, if a user changes their name, the original name stays in the cache for at least 1 hour (extendable by using that name as target for item)
|
||||||
// and both are usable to target the same user (id is the same)
|
// and both are usable to target the same user (id is the same)
|
||||||
|
// The only problem would be if a user changed their name and someone else took their name right after
|
||||||
const user = await User.initUsername(msg.chatterName);
|
const user = await User.initUsername(msg.chatterName);
|
||||||
|
|
||||||
if (!unbannableUsers.includes(msg.chatterId)) user?.makeVulnerable(); // Make the user vulnerable to explosions
|
if (!unbannableUsers.includes(msg.chatterId)) user?.makeVulnerable(); // Make the user vulnerable to explosions
|
||||||
|
|||||||
36
bot/items/blaster.ts
Normal file
36
bot/items/blaster.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { Item } from ".";
|
||||||
|
import { sendMessage } from "../commands";
|
||||||
|
import { timeout } from "../lib/timeout";
|
||||||
|
import { User } from "../user";
|
||||||
|
|
||||||
|
export default new Item('blaster', 'Blaster', 's',
|
||||||
|
'Times a specific person out for 60 seconds',
|
||||||
|
['blaster', 'blast'], ['moderator:manage:banned_users'],
|
||||||
|
async (msg, user) => {
|
||||||
|
const slicecount = msg.messageText.startsWith('!use') ? 2 : 1;
|
||||||
|
const messagequery = msg.messageText.trim().split(' ').slice(slicecount);
|
||||||
|
if (!messagequery[0]) { await sendMessage('Please specify a target'); return; };
|
||||||
|
const target = await User.initUsername(messagequery[0].toLowerCase());
|
||||||
|
if (!target) { await sendMessage(`${messagequery[0]} doesn't exist`); return; };
|
||||||
|
const result = await timeout(target, `You got blasted by ${user.displayName}!`, 60);
|
||||||
|
if (result.status) await Promise.all([
|
||||||
|
sendMessage(`GOTTEM ${target.displayName} got BLASTED by ${user.displayName} GOTTEM`)
|
||||||
|
]);
|
||||||
|
else {
|
||||||
|
switch (result.reason) {
|
||||||
|
case "banned":
|
||||||
|
await sendMessage(`${target.displayName} is already timed out/banned`, msg.messageId);
|
||||||
|
break;
|
||||||
|
case "illegal":
|
||||||
|
await Promise.all([
|
||||||
|
sendMessage(`${user.displayName} Nou Nou Nou`),
|
||||||
|
timeout(user, `You can't just shoot ${target.displayName}!`, 60)
|
||||||
|
]);
|
||||||
|
break;
|
||||||
|
case "unknown":
|
||||||
|
await sendMessage('Something went wrong...', msg.messageId);
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
@@ -2,18 +2,14 @@ import { streamerApi, streamerId, unbannableUsers } from "..";
|
|||||||
import { User } from "../user";
|
import { User } from "../user";
|
||||||
|
|
||||||
type SuccessfulTimeout = { status: true };
|
type SuccessfulTimeout = { status: true };
|
||||||
type UnSuccessfulTimeout = { status: false; reason: 'noexist' | 'banned' | 'unknown' | 'illegal' };
|
type UnSuccessfulTimeout = { status: false; reason: 'banned' | 'unknown' | 'illegal' };
|
||||||
type TimeoutResult = SuccessfulTimeout | UnSuccessfulTimeout;
|
type TimeoutResult = SuccessfulTimeout | UnSuccessfulTimeout;
|
||||||
|
|
||||||
/** Give a user a timeout/ban
|
/** Give a user a timeout/ban
|
||||||
* @param target - userid or User class to timeout/ban
|
* @param user - user class of target to timeout/ban
|
||||||
* @param reason - reason for timeout/ban
|
* @param reason - reason for timeout/ban
|
||||||
* @param duration - duration of timeout. don't specifiy for ban */
|
* @param duration - duration of timeout. don't specifiy for ban */
|
||||||
export const timeout = async (target: string | User, reason: string, duration?: number): Promise<TimeoutResult> => {
|
export const timeout = async (user: User, reason: string, duration?: number): Promise<TimeoutResult> => {
|
||||||
// set the user object to either the predefined user obj or a new user obj
|
|
||||||
const user = typeof (target) === 'string' ? await User.initUsername(target) : target;
|
|
||||||
if (!user) return { status: false, reason: 'noexist' };
|
|
||||||
|
|
||||||
if (unbannableUsers.includes(user.id)) return { status: false, reason: 'illegal' };
|
if (unbannableUsers.includes(user.id)) return { status: false, reason: 'illegal' };
|
||||||
|
|
||||||
// Check if user already has a timeout
|
// Check if user already has a timeout
|
||||||
|
|||||||
Reference in New Issue
Block a user