/
general.clj
83 lines (69 loc) · 3.34 KB
/
general.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(ns discord.extensions.general
(:require [clojure.string :as s]
[discord.bot :as bot]
[discord.embeds :as e]
[discord.http :as http]
[discord.utils :as utils]))
(bot/defcommand say [client message]
"Tells the bot to echo back the content of your message."
(bot/say (:content message)))
(bot/defcommand botsay [client message]
"Tells the bot to echo back the content of your message and then deletes the user's original message."
(bot/say (:content message))
(bot/delete message))
(bot/defcommand working [client message]
"Posts the awesome Star Wars \"IT'S WORKING\" gif into the channel."
(bot/say "https://giphy.com/gifs/9K2nFglCAQClO"))
(bot/defcommand roll [client message]
"Rolls a dice between 1 and the user's supplied value (100 by default)."
(if-let [potential-number (not-empty (:content message))]
(try
(let [limit (Integer/parseInt potential-number)]
(bot/say (format ":game_die: %d :game_die:" (inc (rand-int limit)))))
(catch NumberFormatException _
(bot/say "Error: Please supply a number!")))
(bot/say (format ":game_die: %d :game_die:" (inc (rand-int 100))))))
(bot/defcommand choose [client message]
"Tells the bot to choose one of the options supplied."
(if-let [choices (utils/words (:content message))]
(bot/say (rand-nth choices))
(bot/say "Error: Nothing to choose from!")))
(bot/defcommand servers [client message]
"Lists the servers that the bot is a part of."
(let [bot-servers (http/get-servers client)]
(->> bot-servers
(map :name)
(s/join \newline)
(format "Servers I'm a part of: \n%s")
(bot/say))))
(bot/defcommand flip [client message]
"Tells the bot to flip a coin."
(bot/say (format "Flipping a coin....%s" (rand-nth ["Heads" "Tails"]))))
(bot/defcommand rps [client message]
"Plays Rock, Paper, Scissors with the bot"
(if-let [user-choice (-> message :content utils/words first keyword)]
(if (some #{user-choice} [:rock :paper :scissors])
(let [bot-choice (rand-nth [:rock :paper :scissors])]
(condp = [user-choice bot-choice]
;; Tie choices
[:rock :rock] (bot/say ":moyai: We're even! :moyai:")
[:paper :paper] (bot/say ":newspaper: We're even! :newspaper:")
[:scissors :scissors] (bot/say ":scissors: We're even! :scissors:")
[:rock :paper] (bot/say ":newspaper: I win! :newspaper:")
[:rock :scissors] (bot/say ":scissors: You win! :scissors:")
[:paper :rock] (bot/say ":moyai: You win! :moyai:")
[:paper :scissors] (bot/say ":scissors: I win! :scissors:")
[:scissors :rock] (bot/say ":moyai: I win! :moyai:")
[:scissors :paper] (bot/say ":newspaper: You win! :newspaper:")))
(bot/say "Please choose either rock, paper, or scissors."))
(bot/say "Please choose either rock, paper, or scissors.")))
(bot/defcommand count [client message]
(if-let [potential-number (not-empty (:content message))]
(try
(let [count-limit (Integer/parseInt potential-number)]
(doseq [n (range count-limit)]
(bot/say (format "Number: %d" n))))
(catch NumberFormatException _
(bot/say "Error: Please supply a number!")))
(doseq [n (range 10)]
(bot/say (format "Number: %d" n)))))