Lint
This commit is contained in:
parent
76f523ae78
commit
d7595cb3dd
1 changed files with 9 additions and 10 deletions
|
|
@ -31,9 +31,9 @@ const settings = definePluginSettings({
|
||||||
});
|
});
|
||||||
|
|
||||||
const isLegal = (word: string): boolean => {
|
const isLegal = (word: string): boolean => {
|
||||||
if (word == "i" || word == "I") return false;
|
if (word === "i" || word === "I") return false;
|
||||||
if (word == "http" || word == "https") return false;
|
if (word === "http" || word === "https") return false;
|
||||||
|
|
||||||
const lastChar = word.slice(-1).toLowerCase();
|
const lastChar = word.slice(-1).toLowerCase();
|
||||||
if (["a", "e", "o", "u", "y"].includes(lastChar)) return false;
|
if (["a", "e", "o", "u", "y"].includes(lastChar)) return false;
|
||||||
|
|
||||||
|
|
@ -43,13 +43,13 @@ const isLegal = (word: string): boolean => {
|
||||||
const getWordBoundaries = (string: string): WordMatch[] => {
|
const getWordBoundaries = (string: string): WordMatch[] => {
|
||||||
const regex = /[.,!?;:'"\-_()[\]{}<>/\\|@#$%^&*+=`~…—–\s0-9]+/g;
|
const regex = /[.,!?;:'"\-_()[\]{}<>/\\|@#$%^&*+=`~…—–\s0-9]+/g;
|
||||||
|
|
||||||
let matches: WordMatch[] = [];
|
const matches: WordMatch[] = [];
|
||||||
let startIndex: number = 0;
|
let startIndex: number = 0;
|
||||||
|
|
||||||
for (const match of string.matchAll(regex)) {
|
for (const match of string.matchAll(regex)) {
|
||||||
const word = string.slice(startIndex, match.index);
|
const word = string.slice(startIndex, match.index);
|
||||||
if (word.length > 0) {
|
if (word.length > 0) {
|
||||||
matches.push({word, startIndex});
|
matches.push({ word, startIndex });
|
||||||
}
|
}
|
||||||
|
|
||||||
startIndex = match.index + match[0].length;
|
startIndex = match.index + match[0].length;
|
||||||
|
|
@ -57,7 +57,7 @@ const getWordBoundaries = (string: string): WordMatch[] => {
|
||||||
|
|
||||||
if (startIndex < string.length) {
|
if (startIndex < string.length) {
|
||||||
const word = string.slice(startIndex);
|
const word = string.slice(startIndex);
|
||||||
matches.push({word, startIndex});
|
matches.push({ word, startIndex });
|
||||||
}
|
}
|
||||||
|
|
||||||
return matches;
|
return matches;
|
||||||
|
|
@ -71,8 +71,8 @@ const chooseRandomWord = (message: string): WordMatch | null => {
|
||||||
const wordMatch: WordMatch = words[index];
|
const wordMatch: WordMatch = words[index];
|
||||||
|
|
||||||
if (!isLegal(wordMatch.word)) {
|
if (!isLegal(wordMatch.word)) {
|
||||||
words.splice(index, 1);
|
words.splice(index, 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return wordMatch;
|
return wordMatch;
|
||||||
|
|
@ -100,7 +100,7 @@ const handleMessage = ((channelId, message) => {
|
||||||
const wordMatch: WordMatch | null = chooseRandomWord(msg);
|
const wordMatch: WordMatch | null = chooseRandomWord(msg);
|
||||||
if (wordMatch === null) return;
|
if (wordMatch === null) return;
|
||||||
|
|
||||||
const word = wordMatch.word;
|
const { word } = wordMatch;
|
||||||
const wordLower = word.toLowerCase();
|
const wordLower = word.toLowerCase();
|
||||||
const isLower = word === wordLower;
|
const isLower = word === wordLower;
|
||||||
|
|
||||||
|
|
@ -113,7 +113,6 @@ const handleMessage = ((channelId, message) => {
|
||||||
message.content = msg.slice(0, idx) + append + msg.slice(idx);
|
message.content = msg.slice(0, idx) + append + msg.slice(idx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const IngtoninatorButton: ChatBarButtonFactory = ({ isMainChat }) => {
|
const IngtoninatorButton: ChatBarButtonFactory = ({ isMainChat }) => {
|
||||||
const { isEnabled, showIcon } = settings.use(["isEnabled", "showIcon"]);
|
const { isEnabled, showIcon } = settings.use(["isEnabled", "showIcon"]);
|
||||||
const toggle = () => settings.store.isEnabled = !settings.store.isEnabled;
|
const toggle = () => settings.store.isEnabled = !settings.store.isEnabled;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue