-
Notifications
You must be signed in to change notification settings - Fork 0
/
SGir.scala
executable file
·145 lines (127 loc) · 4.11 KB
/
SGir.scala
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package antitech.sgir
import model.{User, MongoConfig}
import org.jibble.pircbot.PircBot
import org.joda.time.DateTime
import com.foursquare.rogue.Rogue._
object SGir extends PircBot {
private val config = Config.config
private val botName = config.getString("botName").get
private val adminHost = config.getString("adminHost").get
setName(botName)
setLogin(botName)
MongoConfig.init
/**
* Will check everyone in each channel we are in into our system.
*/
def checkChannelIn = {
val allUsers = ""
}
// Is called whenever any message is sent.
override def onMessage(chan: String, sender: String,
login: String, host: String,
msg: String): Unit = {
// = Commands are for Admin and Control.
if (msg.startsWith("=") && isAdminHost(host)) {
// First check hostname in order to allow commands.
val command = msg.split(" ").head.toLowerCase
val arguments = msg.split(" ").drop(1).toList
command match {
case "=join" =>
joinChannel(arguments.head)
case "=say" => sendMessage(chan,
arguments.reduceLeft[String] {
(y, z) => y + " " + z
})
case "=reload" => config.reload()
case "=exit" => System.exit(1)
case "=reverse" => sendMessage(chan,
arguments.reduceLeft[String] {
(y, z) => z + " " + y
})
case "=op" =>
arguments.foreach(op(chan, _))
case "=deop" =>
arguments.foreach(deOp(chan, _))
case _ => None
}
}
// ! commands are for everyone.
else if (msg.startsWith("!")) {
val commArg: List[String] = parseCommand(msg)
commArg(0) match {
case "!say" =>
sendMessage(chan, sender + " wants me to say: " +
commArg(1))
case _ => None
}
}
if (msg.toLowerCase().startsWith("sgir")) {
val speak = Speak.getQuote(msg)
if (speak != "") {
sendMessage(chan, speak)
}
else {
sendMessage(chan, "[o_O]")
}
}
}
// Action thrown whenever anyone is kicked in
// any channel the bot exists.
override def onKick(chan: String, kicker: String,
kickerLogin: String, kickerHost: String,
kickedNick: String, reason: String): Unit = {
if (kickedNick.startsWith("digicyc")) {
kick(chan, kicker, "Don't Kick the MAN!")
}
if (kickedNick.startsWith("SGir")) {
joinChannel(chan)
sendMessage(chan, kicker + ": Don't be an ass.")
kick(chan, kicker, "BOOOM! HS!")
}
}
// Check if the current users host is that of the admins.
def isAdminHost(hostName: String): Boolean = {
hostName.startsWith(adminHost)
}
override def onJoin(channel: String, joiner: String, login: String, hostname: String) {
isOps(joiner, hostname, channel)
checkIn(channel, joiner, login, hostname)
}
def checkIn(channel: String, joiner: String, login: String, hostname: String): User = {
val user = User where (_.hostname eqs hostname) get
if (user == None) {
// If no user can be found then we create em.
val newUser = User.createRecord.alias(joiner)
newUser.name("")
newUser.channel(channel)
newUser.hostname(hostname)
newUser.karma(0)
newUser.is_admin(false)
newUser.logged_on(new DateTime)
newUser.save
newUser
} else {
User where (_.hostname eqs hostname) modify (_.logged_on setTo new DateTime) and
(_.alias setTo joiner)
user.get
}
}
def isOps(joiner: String, hostname: String, channel: String) {
config.getList("opsList").foreach {
isOps =>
if (hostname == isOps) {
op(channel, joiner)
}
}
}
// Parse out the message sent for any possible commands.
def parseCommand(msg: String): List[String] = {
val command = msg.split(" ").head.toLowerCase
val argument = msg.replace(command + " ", "")
List(command, argument)
}
def main(args: Array[String]): Unit = {
connect(Config.config("ircServer"))
Config.config.getList("channels").foreach(joinChannel(_))
}
}