Skip to content

Commit db01103

Browse files
added the ability to use channels with password, fixes 35
1 parent e22d58c commit db01103

7 files changed

+80
-45
lines changed

README.md

+26-12
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Which LLM provider to use. The supported options are:
7878
- [ollama](https://github.com/ollama/ollama)
7979
- chatgpt
8080
- gemini
81+
- [openrouter](https://openrouter.ai/)
8182

8283
#### apikey
8384

@@ -170,9 +171,12 @@ admins = ["admin1", "admin2"]
170171
List of channels for the bot to join when it connects to the server.
171172

172173
```
173-
ircChannels = ["#channel1", "#channel2"]
174+
ircChannels = [["#channel1","channel1password"], ["#channel2",""], ["#channel3"]]
174175
```
175176

177+
In the provided example, milla will attempt to join `#channel1` with the provided password while for the other two channels, it will try to join normally.<br/>
178+
This behaviour is consistant across all places where a channel name is the input.<br/>
179+
176180
Please note that the bot does not have to join a channel to be usable. One can simply query the bot directly as well.<br/>
177181

178182
#### databaseUser
@@ -195,6 +199,10 @@ Name of the database.
195199

196200
List of channels that the bot will scrape into a database table. You can later on use these databases for the custom commands.<br/>
197201

202+
```
203+
ircChannels = [["#channel1","channel1password"], ["#channel2",""], ["#channel3"]]
204+
```
205+
198206
#### ircProxy
199207

200208
Determines which proxy to use to connect to the IRC network:
@@ -293,9 +301,9 @@ Watchlists allow you to specify a list of channels to watch. The watched values
293301

294302
```toml
295303
[ircd.devinet_terra.watchlist.security]
296-
watchList = ["#securityfeeds"]
304+
watchList = [["#securityfeeds"]]
297305
watchFiles = ["/watchfiles/voidbox.list"]
298-
alertChannel = "#milla_alerts"
306+
alertChannel = ["#milla_alerts"]
299307
eventTypes = ["PRIVMSG"]
300308
fgColor = 0
301309
bgColor = 28
@@ -339,7 +347,7 @@ ircNick = "milla"
339347
enableSasl = true
340348
ircSaslUser = "milla"
341349
ircSaslPass = "xxxxx"
342-
ircChannels = ["##chan1", "##chan2"]
350+
ircChannels = [["##chan1"], ["##chan2"]]
343351
temp = 0.2
344352
requestTimeout = 10
345353
millaReconnectDelay = 60
@@ -356,7 +364,7 @@ databaseAddress = "postgres:5432"
356364
databasePassword = "changeme"
357365
databaseUser = "devi"
358366
databaseName = "milla"
359-
scrapeChannels = ["#soulhack", "#warroom", "#securityfeeds"]
367+
scrapeChannels = [["#soulhack"], ["#warroom"], ["#securityfeeds"]]
360368
ircProxy = "socks5://127.0.0.1:9050"
361369
llmProxy = "http://127.0.0.1:8180"
362370
skipTLSVerify = false
@@ -365,18 +373,18 @@ adminOnly = false
365373
plugins = ["/plugins/ip.lua", "/plugins/urban.lua"]
366374
context = ["please respond in french even if i use another language unless you are specifically asked to use any language other than french"]
367375
[ircd.devinet.watchlist.security]
368-
watchList = ["#securityfeeds"]
376+
watchList = [["#securityfeeds"]]
369377
watchFiles = ["/watchfiles/voidbox.list"]
370-
alertChannel = "#milla_alerts"
378+
alertChannel = ["#milla_alerts"]
371379
eventTypes = ["PRIVMSG"]
372380
fgColor = 0
373381
bgColor = 28
374382
[ircd.devinet.rss.manga]
375383
rssFile = "/rssfeeds/manga.json"
376-
channel = "#manga"
384+
channel = ["#manga"]
377385
[ircd.devinet.rss.anime]
378386
rssFile = "/rssfeeds/anime.json"
379-
channel = "#anime"
387+
channel = ["#anime"]
380388

381389
[ircd.liberanet]
382390
ircServer = "irc.libera.chat"
@@ -399,7 +407,7 @@ useTLS = true
399407
disableSTSFallback = true
400408
allowFlood = false
401409
admins = ["noone_has_this_nick"]
402-
ircChannels = ["##milla1", "##milla2"]
410+
ircChannels = [["##milla1"], ["##milla2"]]
403411
debug = true
404412
out = true
405413
ircProxy = "socks5://127.0.0.1:9051"
@@ -441,7 +449,7 @@ Returns memory stats for milla.
441449

442450
#### join
443451

444-
Joins a channel: `/join #channel`
452+
Joins a channel: `/join #channel [optional_password]`
445453

446454
#### leave
447455

@@ -719,9 +727,11 @@ milla.send_message(msg, target)
719727
```
720728

721729
```lua
722-
milla.join_channel(channel)
730+
milla.join_channel(channel,password)
723731
```
724732

733+
Please note that even if the channel doesn't have a password, it still will require the second argument and the second argument must be empty.
734+
725735
```lua
726736
milla.part_channel(channel)
727737
```
@@ -738,6 +748,10 @@ milla.send_gemini_request(prompt)
738748
milla.send_chatgpt_request(prompt)
739749
```
740750

751+
```lua
752+
milla.send_or_request(prompt)
753+
```
754+
741755
```lua
742756
milla.query_db(query)
743757
```

config-example.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ircNick = "milla"
55
enableSasl = true
66
ircSaslUser = "milla"
77
ircSaslPass = "xxxxx"
8-
ircChannels = ["##chan1", "##chan2"]
8+
ircChannels = [["##chan1"], ["##chan2"]]
99
temp = 0.2
1010
requestTimeout = 10
1111
millaReconnectDelay = 60
@@ -22,7 +22,7 @@ databaseAddress = "postgres:5432"
2222
databasePassword = "changeme"
2323
databaseUser = "devi"
2424
databaseName = "milla"
25-
scrapeChannels = ["#soulhack", "#warroom", "#securityfeeds"]
25+
scrapeChannels = [["#soulhack"], ["#warroom"], ["#securityfeeds"]]
2626
ircProxy = "socks5://127.0.0.1:9050"
2727
llmProxy = "http://127.0.0.1:8180"
2828
skipTLSVerify = false
@@ -31,18 +31,18 @@ adminOnly = false
3131
context = ["please respond in french even if i use another language unless you are specifically asked to use any language other than french", "your name is terra"]
3232
plugins = ["/plugins/ip.lua", "/plugins/urban.lua"]
3333
[ircd.devinet.watchlist.security]
34-
watchList = ["#securityfeeds"]
34+
watchList = [["#securityfeeds"]]
3535
watchFiles = ["/watchfiles/voidbox.list"]
36-
alertChannel = "#milla_alerts"
36+
alertChannel = ["#milla_alerts"]
3737
eventTypes = ["PRIVMSG"]
3838
fgColor = 0
3939
bgColor = 28
4040
[ircd.devinet.rss.manga]
4141
rssFile = "/rssfeeds/manga.json"
42-
channel = "#manga"
42+
channel = ["#manga"]
4343
[ircd.devinet.rss.anime]
4444
rssFile = "/rssfeeds/anime.json"
45-
channel = "#anime"
45+
channel = ["#anime"]
4646

4747
[ircd.liberanet]
4848
ircServer = "irc.libera.chat"
@@ -65,7 +65,7 @@ useTLS = true
6565
disableSTSFallback = true
6666
allowFlood = false
6767
admins = ["noone_has_this_nick"]
68-
ircChannels = ["##milla1", "##milla2"]
68+
ircChannels = [["##milla1"], ["##milla2"]]
6969
debug = true
7070
out = true
7171
ircProxy = "socks5://127.0.0.1:9051"

main.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,11 @@ func runCommand(
518518

519519
break
520520
}
521-
522-
client.Cmd.Join(args[1])
521+
if len(args) == 3 {
522+
IrcJoin(client, []string{args[1], args[2]})
523+
} else {
524+
client.Cmd.Join(args[1])
525+
}
523526
case "leave":
524527
if !isFromAdmin(appConfig.Admins, event) {
525528
break
@@ -1165,7 +1168,7 @@ func connectToDB(appConfig *TomlConfig, ctx *context.Context, poolChan chan *pgx
11651168
log.Printf("%s connected to database", appConfig.IRCDName)
11661169

11671170
for _, channel := range appConfig.ScrapeChannels {
1168-
tableName := getTableFromChanName(channel, appConfig.IRCDName)
1171+
tableName := getTableFromChanName(channel[0], appConfig.IRCDName)
11691172
query := fmt.Sprintf(
11701173
`create table if not exists %s (
11711174
id serial primary key,
@@ -1241,7 +1244,7 @@ func WatchListHandler(irc *girc.Client, appConfig TomlConfig) {
12411244
for _, channel := range watchlist.WatchList {
12421245
isRightEventType = false
12431246

1244-
if channel == event.Params[0] {
1247+
if channel[0] == event.Params[0] {
12451248

12461249
for _, eventType := range watchlist.EventTypes {
12471250
if eventType == event.Command {
@@ -1268,7 +1271,7 @@ func WatchListHandler(irc *girc.Client, appConfig TomlConfig) {
12681271
"\x1b[0m" + event.Last()[indexes[0]+1+nextWhitespaceIndex:]
12691272

12701273
irc.Cmd.Message(
1271-
watchlist.AlertChannel,
1274+
watchlist.AlertChannel[0],
12721275
fmt.Sprintf("%s: %s", watchname, rewrittenMessage))
12731276

12741277
log.Printf("matched from watchlist -- %s: %s", watchname, event.Last())
@@ -1356,7 +1359,7 @@ func runIRC(appConfig TomlConfig) {
13561359

13571360
irc.Handlers.AddBg(girc.CONNECTED, func(c *girc.Client, _ girc.Event) {
13581361
for _, channel := range appConfig.IrcChannels {
1359-
c.Cmd.Join(channel)
1362+
IrcJoin(irc, channel)
13601363
}
13611364
})
13621365

@@ -1413,7 +1416,7 @@ func runIRC(appConfig TomlConfig) {
14131416
if len(appConfig.ScrapeChannels) > 0 {
14141417
irc.Handlers.AddBg(girc.CONNECTED, func(c *girc.Client, _ girc.Event) {
14151418
for _, channel := range appConfig.ScrapeChannels {
1416-
c.Cmd.Join(channel)
1419+
IrcJoin(irc, channel)
14171420
}
14181421
})
14191422

@@ -1424,10 +1427,10 @@ func runIRC(appConfig TomlConfig) {
14241427
irc.Handlers.AddBg(girc.CONNECTED, func(client *girc.Client, _ girc.Event) {
14251428
for _, watchlist := range appConfig.WatchLists {
14261429
log.Print("joining ", watchlist.AlertChannel)
1427-
client.Cmd.Join(watchlist.AlertChannel)
1430+
IrcJoin(irc, watchlist.AlertChannel)
14281431

14291432
for _, channel := range watchlist.WatchList {
1430-
client.Cmd.Join(channel)
1433+
IrcJoin(irc, channel)
14311434
}
14321435
}
14331436
})

plugins.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,13 @@ func registerLuaCommand(luaState *lua.LState, appConfig *TomlConfig) func(*lua.L
221221
func ircJoinChannelClosure(luaState *lua.LState, client *girc.Client) func(*lua.LState) int {
222222
return func(luaState *lua.LState) int {
223223
channel := luaState.CheckString(1)
224+
password := luaState.CheckString(2)
224225

225-
client.Cmd.Join(channel)
226+
if password != "" {
227+
client.Cmd.JoinKey(channel, password)
228+
} else {
229+
client.Cmd.Join(channel)
230+
}
226231

227232
return 0
228233
}

rss.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
func GetFeed(feed FeedConfig,
2222
client *girc.Client,
2323
pool *pgxpool.Pool,
24-
channel, groupName string,
24+
channel []string,
25+
groupName string,
2526
) {
2627
rowName := groupName + "__" + feed.Name + "__"
2728

@@ -55,7 +56,7 @@ func GetFeed(feed FeedConfig,
5556

5657
for _, item := range parsedFeed.Items {
5758
if item.PublishedParsed.Unix() > newestFromDB {
58-
client.Cmd.Message(channel, parsedFeed.Title+": "+item.Title+">>>"+item.Link)
59+
client.Cmd.Message(channel[0], parsedFeed.Title+": "+item.Title+">>>"+item.Link)
5960
}
6061
}
6162

@@ -77,7 +78,8 @@ func feedDispatcher(
7778
config RSSConfig,
7879
client *girc.Client,
7980
pool *pgxpool.Pool,
80-
channel, groupName string,
81+
channel []string,
82+
groupName string,
8183
period int,
8284
) {
8385
for {
@@ -164,7 +166,7 @@ func runRSS(appConfig *TomlConfig, client *girc.Client) {
164166

165167
for groupName, rss := range appConfig.Rss {
166168
log.Print("RSS: joining ", rss.Channel)
167-
client.Cmd.Join(rss.Channel)
169+
IrcJoin(client, rss.Channel)
168170
rssConfig := ParseRSSConfig(rss.RssFile)
169171
if rssConfig == nil {
170172
log.Print("Could not parse RSS config file " + rss.RssFile + ". Exiting.")

types.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ type LuaLstates struct {
3232
}
3333

3434
type WatchList struct {
35-
AlertChannel string `toml:"alertChannel"`
36-
WatchList []string `toml:"watchList"`
37-
WatchFiles []string `toml:"watchFiles"`
38-
Words []string `toml:"watchWords"`
39-
EventTypes []string `toml:"eventTypes"`
40-
FGColor int `toml:"fgColor"`
41-
BGColor int `toml:"bgColor"`
35+
AlertChannel []string `toml:"alertChannel"`
36+
WatchList [][]string `toml:"watchList"`
37+
WatchFiles []string `toml:"watchFiles"`
38+
Words []string `toml:"watchWords"`
39+
EventTypes []string `toml:"eventTypes"`
40+
FGColor int `toml:"fgColor"`
41+
BGColor int `toml:"bgColor"`
4242
}
4343

4444
type LuaCommand struct {
@@ -47,8 +47,8 @@ type LuaCommand struct {
4747
}
4848

4949
type RssFile struct {
50-
RssFile string `toml:"rssFile"`
51-
Channel string `toml:"channel"`
50+
RssFile string `toml:"rssFile"`
51+
Channel []string `toml:"channel"`
5252
}
5353

5454
type TomlConfig struct {
@@ -106,9 +106,9 @@ type TomlConfig struct {
106106
Out bool `toml:"out"`
107107
AdminOnly bool `toml:"adminOnly"`
108108
pool *pgxpool.Pool
109-
Admins []string `toml:"admins"`
110-
IrcChannels []string `toml:"ircChannels"`
111-
ScrapeChannels []string `toml:"scrapeChannels"`
109+
Admins []string `toml:"admins"`
110+
IrcChannels [][]string `toml:"ircChannels"`
111+
ScrapeChannels [][]string `toml:"scrapeChannels"`
112112
}
113113

114114
func (config *TomlConfig) insertLState(

utils.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import "github.com/lrstanley/girc"
4+
5+
func IrcJoin(irc *girc.Client, channel []string) {
6+
if len(channel) >= 0 && channel[0] == "" {
7+
irc.Cmd.JoinKey(channel[0], channel[1])
8+
} else {
9+
irc.Cmd.Join(channel[0])
10+
}
11+
}

0 commit comments

Comments
 (0)