| 1939 | } | 1965 | } |
| 1940 | } | 1966 | } |
| 1941 | | 1967 | |
| | 1968 | /** |
| | 1969 | * |
| | 1970 | * @param {{title?: string, severity?: string, timeout?: string, extendedTimeout?: string, preventDuplicates?: string, awaitDismissal?: string}} args - named arguments from the slash command |
| | 1971 | * @param {string} value - The string to echo (unnamed argument from the slash command) |
| | 1972 | * @returns {Promise<string>} The text that was echoed |
| | 1973 | */ |
| 1942 | async function echoCallback(args, value) { | 1974 | async function echoCallback(args, value) { |
| 1943 | // Note: We don't need to sanitize input, as toastr is set up by default to escape HTML via toastr options | 1975 | // Note: We don't need to sanitize input, as toastr is set up by default to escape HTML via toastr options |
| 1944 | if (value === '') { | 1976 | if (value === '') { |
| 1945 | console.warn('WARN: No argument provided for /echo command'); | 1977 | console.warn('WARN: No argument provided for /echo command'); |
| 1946 | return; | 1978 | return ''; |
| | 1979 | } |
| | 1980 | |
| | 1981 | if (args.severity && !['error', 'warning', 'success', 'info'].includes(args.severity)) { |
| | 1982 | toastr.warning(`Invalid severity provided for /echo command: ${args.severity}`); |
| | 1983 | args.severity = null; |
| | 1984 | } |
| | 1985 | |
| | 1986 | const title = args.title ? args.title : undefined; |
| | 1987 | const severity = args.severity ? args.severity : 'info'; |
| | 1988 | |
| | 1989 | /** @type {ToastrOptions} */ |
| | 1990 | const options = {}; |
| | 1991 | if (args.timeout && !isNaN(parseInt(args.timeout))) options.timeOut = parseInt(args.timeout); |
| | 1992 | if (args.extendedTimeout && !isNaN(parseInt(args.extendedTimeout))) options.extendedTimeOut = parseInt(args.extendedTimeout); |
| | 1993 | if (isTrueBoolean(args.preventDuplicates)) options.preventDuplicates = true; |
| | 1994 | |
| | 1995 | // Prepare possible await handling |
| | 1996 | let awaitDismissal = isTrueBoolean(args.awaitDismissal); |
| | 1997 | let resolveToastDismissal; |
| | 1998 | |
| | 1999 | if (awaitDismissal) { |
| | 2000 | options.onHidden = () => resolveToastDismissal(value); |
| 1947 | } | 2001 | } |
| 1948 | const title = args?.title !== undefined && typeof args?.title === 'string' ? args.title : undefined; | 2002 | |
| 1949 | const severity = args?.severity !== undefined && typeof args?.severity === 'string' ? args.severity : 'info'; | | |
| 1950 | switch (severity) { | 2003 | switch (severity) { |
| 1951 | case 'error': | 2004 | case 'error': |
| 1952 | toastr.error(value, title); | 2005 | toastr.error(value, title, options); |
| 1953 | break; | 2006 | break; |
| 1954 | case 'warning': | 2007 | case 'warning': |
| 1955 | toastr.warning(value, title); | 2008 | toastr.warning(value, title, options); |
| 1956 | break; | 2009 | break; |
| 1957 | case 'success': | 2010 | case 'success': |
| 1958 | toastr.success(value, title); | 2011 | toastr.success(value, title, options); |
| 1959 | break; | 2012 | break; |
| 1960 | case 'info': | 2013 | case 'info': |
| 1961 | default: | 2014 | default: |
| 1962 | toastr.info(value, title); | 2015 | toastr.info(value, title, options); |
| 1963 | break; | 2016 | break; |
| 1964 | } | 2017 | } |
| 1965 | return value; | 2018 | |
| | 2019 | if (awaitDismissal) { |
| | 2020 | return new Promise((resolve) => { |
| | 2021 | resolveToastDismissal = resolve; |
| | 2022 | }); |
| | 2023 | } else { |
| | 2024 | return value; |
| | 2025 | } |
| 1966 | } | 2026 | } |
| 1967 | | 2027 | |
| | 2028 | |
| 1968 | async function addSwipeCallback(_, arg) { | 2029 | async function addSwipeCallback(_, arg) { |
| 1969 | const lastMessage = chat[chat.length - 1]; | 2030 | const lastMessage = chat[chat.length - 1]; |
| 1970 | | 2031 | |