-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
162 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Message } from "https://deno.land/x/discordeno@10.1.0/mod.ts"; | ||
import { getScore, REACTION_SCORES } from "./scoring.ts"; | ||
|
||
const COMMAND_TRIGGER = "ph8"; | ||
|
||
const commandHandlers: { | ||
[command: string]: ( | ||
message: Message, | ||
...args: Array<string | undefined> | ||
) => void; | ||
} = { | ||
help(message, topic) { | ||
if (!topic) { | ||
message.reply( | ||
[ | ||
"Topics: `scoring`.", | ||
"", | ||
`Say "${COMMAND_TRIGGER} help [topic]".`, | ||
].join("\n") | ||
); | ||
return; | ||
} | ||
|
||
switch (topic) { | ||
case "scoring": | ||
message.reply( | ||
[ | ||
"You can react to messages with certain emoji to add or subtract from a users score.", | ||
"", | ||
"Reactions and their values: ", | ||
...Object.keys(REACTION_SCORES).map( | ||
(emoji) => `${emoji} == ${REACTION_SCORES[emoji]}` | ||
), | ||
"", | ||
`You can retrieve your score by saying "${COMMAND_TRIGGER} my score".`, | ||
`You can retrieve other users\' scores by saying "${COMMAND_TRIGGER} score @username".`, | ||
].join("\n") | ||
); | ||
break; | ||
} | ||
}, | ||
my(message, subCommand) { | ||
if (subCommand === "score") { | ||
const score = getScore(message.author.id); | ||
message.reply(`${score || 0}`); | ||
} | ||
}, | ||
|
||
score(message) { | ||
if (message.mentions.length) { | ||
message.reply( | ||
message.mentions | ||
.map((userID) => { | ||
const score = getScore(userID); | ||
return `<@${userID}> has ${score} points`; | ||
}) | ||
.join("\n") | ||
); | ||
} | ||
}, | ||
}; | ||
|
||
export const handleCommands = (message: Message) => { | ||
if (!message.content.toLowerCase().startsWith(COMMAND_TRIGGER)) return; | ||
|
||
const [, command, ...args] = message.content.split(" "); | ||
|
||
console.log({ command, args }); | ||
|
||
if (!command) { | ||
message.reply("Yeah, bud?"); | ||
return true; | ||
} | ||
|
||
const handler = commandHandlers[command]; | ||
if (handler) { | ||
handler(message, ...args); | ||
return true; | ||
} | ||
|
||
message.reply("I'm not sure what that means, m8."); | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { Message } from "https://deno.land/x/discordeno@10.1.0/mod.ts"; | ||
import config from "./config.ts"; | ||
import { pickRandom } from "./utils.ts"; | ||
|
||
const REPLIES = ["uhhhh....", "yikeees.", "hahhahhahahahaha", "oh boy", "🍿🤡"]; | ||
|
||
export const handlePoorSources = (message: Message) => { | ||
if (!config.POOR_SOURCES) return; | ||
if (!config.POOR_SOURCES?.length) return; | ||
|
||
const poorSources = config.POOR_SOURCES.join("|"); | ||
const re = new RegExp(`https?:\/\/(?: ${poorSources})`, "gi"); | ||
const re = new RegExp(`https?://(?:[a-z]+.)+(?:${poorSources})`, "gi"); | ||
|
||
if (!re.test(message.content)) return; | ||
|
||
message.reply('uhh.... :grimace:'); | ||
message.reply(pickRandom(REPLIES)); | ||
|
||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
MessageReactionUncachedPayload, | ||
ReactionPayload, | ||
Message, | ||
} from "https://deno.land/x/discordeno@10.1.0/mod.ts"; | ||
import { getScore, REACTION_SCORES, setScore } from "./scoring.ts"; | ||
|
||
interface ReactionHandler { | ||
( | ||
payload: MessageReactionUncachedPayload, | ||
emoji: ReactionPayload, | ||
userID: string, | ||
message?: Message, | ||
removal?: Boolean | ||
): any; | ||
} | ||
|
||
export const handleReactions: ReactionHandler = ( | ||
_p, | ||
emoji, | ||
userID, | ||
message, | ||
remove = false | ||
) => { | ||
if (!message) return; | ||
if (!emoji.name?.length) return; | ||
|
||
let value = REACTION_SCORES[emoji.name]; | ||
if (!value) return; | ||
|
||
if (remove) value *= -1; | ||
|
||
const messageAuthorID = message.author.id; | ||
if (!messageAuthorID || messageAuthorID === userID) return; | ||
|
||
let lastScore = getScore(messageAuthorID); | ||
setScore(messageAuthorID, lastScore + value); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const pickRandom = (arr: any[]) => arr[Math.floor(Math.random() * arr.length)]; |