aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-11-04 18:43:06 +0000
committerterminaldweller <devi@terminaldweller.com>2024-11-04 18:43:06 +0000
commitdb0110393f70987c9b87643594d18df935ef91d5 (patch)
treeb61219f1d4238f4b5ad1d3d2b4d8d611115a0f11
parentadded openrouter as a provider (diff)
downloadmilla-db0110393f70987c9b87643594d18df935ef91d5.tar.gz
milla-db0110393f70987c9b87643594d18df935ef91d5.zip
added the ability to use channels with password, fixes 35
-rw-r--r--README.md38
-rw-r--r--config-example.toml14
-rw-r--r--main.go21
-rw-r--r--plugins.go7
-rw-r--r--rss.go10
-rw-r--r--types.go24
-rw-r--r--utils.go11
7 files changed, 80 insertions, 45 deletions
diff --git a/README.md b/README.md
index b6fa514..8e67ac1 100644
--- a/README.md
+++ b/README.md
@@ -78,6 +78,7 @@ Which LLM provider to use. The supported options are:
- [ollama](https://github.com/ollama/ollama)
- chatgpt
- gemini
+- [openrouter](https://openrouter.ai/)
#### apikey
@@ -170,9 +171,12 @@ admins = ["admin1", "admin2"]
List of channels for the bot to join when it connects to the server.
```
-ircChannels = ["#channel1", "#channel2"]
+ircChannels = [["#channel1","channel1password"], ["#channel2",""], ["#channel3"]]
```
+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/>
+This behaviour is consistant across all places where a channel name is the input.<br/>
+
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/>
#### databaseUser
@@ -195,6 +199,10 @@ Name of the database.
List of channels that the bot will scrape into a database table. You can later on use these databases for the custom commands.<br/>
+```
+ircChannels = [["#channel1","channel1password"], ["#channel2",""], ["#channel3"]]
+```
+
#### ircProxy
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
```toml
[ircd.devinet_terra.watchlist.security]
-watchList = ["#securityfeeds"]
+watchList = [["#securityfeeds"]]
watchFiles = ["/watchfiles/voidbox.list"]
-alertChannel = "#milla_alerts"
+alertChannel = ["#milla_alerts"]
eventTypes = ["PRIVMSG"]
fgColor = 0
bgColor = 28
@@ -339,7 +347,7 @@ ircNick = "milla"
enableSasl = true
ircSaslUser = "milla"
ircSaslPass = "xxxxx"
-ircChannels = ["##chan1", "##chan2"]
+ircChannels = [["##chan1"], ["##chan2"]]
temp = 0.2
requestTimeout = 10
millaReconnectDelay = 60
@@ -356,7 +364,7 @@ databaseAddress = "postgres:5432"
databasePassword = "changeme"
databaseUser = "devi"
databaseName = "milla"
-scrapeChannels = ["#soulhack", "#warroom", "#securityfeeds"]
+scrapeChannels = [["#soulhack"], ["#warroom"], ["#securityfeeds"]]
ircProxy = "socks5://127.0.0.1:9050"
llmProxy = "http://127.0.0.1:8180"
skipTLSVerify = false
@@ -365,18 +373,18 @@ adminOnly = false
plugins = ["/plugins/ip.lua", "/plugins/urban.lua"]
context = ["please respond in french even if i use another language unless you are specifically asked to use any language other than french"]
[ircd.devinet.watchlist.security]
-watchList = ["#securityfeeds"]
+watchList = [["#securityfeeds"]]
watchFiles = ["/watchfiles/voidbox.list"]
-alertChannel = "#milla_alerts"
+alertChannel = ["#milla_alerts"]
eventTypes = ["PRIVMSG"]
fgColor = 0
bgColor = 28
[ircd.devinet.rss.manga]
rssFile = "/rssfeeds/manga.json"
-channel = "#manga"
+channel = ["#manga"]
[ircd.devinet.rss.anime]
rssFile = "/rssfeeds/anime.json"
-channel = "#anime"
+channel = ["#anime"]
[ircd.liberanet]
ircServer = "irc.libera.chat"
@@ -399,7 +407,7 @@ useTLS = true
disableSTSFallback = true
allowFlood = false
admins = ["noone_has_this_nick"]
-ircChannels = ["##milla1", "##milla2"]
+ircChannels = [["##milla1"], ["##milla2"]]
debug = true
out = true
ircProxy = "socks5://127.0.0.1:9051"
@@ -441,7 +449,7 @@ Returns memory stats for milla.
#### join
-Joins a channel: `/join #channel`
+Joins a channel: `/join #channel [optional_password]`
#### leave
@@ -719,9 +727,11 @@ milla.send_message(msg, target)
```
```lua
-milla.join_channel(channel)
+milla.join_channel(channel,password)
```
+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.
+
```lua
milla.part_channel(channel)
```
@@ -739,6 +749,10 @@ milla.send_chatgpt_request(prompt)
```
```lua
+milla.send_or_request(prompt)
+```
+
+```lua
milla.query_db(query)
```
diff --git a/config-example.toml b/config-example.toml
index d1c9ba0..7f429b9 100644
--- a/config-example.toml
+++ b/config-example.toml
@@ -5,7 +5,7 @@ ircNick = "milla"
enableSasl = true
ircSaslUser = "milla"
ircSaslPass = "xxxxx"
-ircChannels = ["##chan1", "##chan2"]
+ircChannels = [["##chan1"], ["##chan2"]]
temp = 0.2
requestTimeout = 10
millaReconnectDelay = 60
@@ -22,7 +22,7 @@ databaseAddress = "postgres:5432"
databasePassword = "changeme"
databaseUser = "devi"
databaseName = "milla"
-scrapeChannels = ["#soulhack", "#warroom", "#securityfeeds"]
+scrapeChannels = [["#soulhack"], ["#warroom"], ["#securityfeeds"]]
ircProxy = "socks5://127.0.0.1:9050"
llmProxy = "http://127.0.0.1:8180"
skipTLSVerify = false
@@ -31,18 +31,18 @@ adminOnly = false
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"]
plugins = ["/plugins/ip.lua", "/plugins/urban.lua"]
[ircd.devinet.watchlist.security]
-watchList = ["#securityfeeds"]
+watchList = [["#securityfeeds"]]
watchFiles = ["/watchfiles/voidbox.list"]
-alertChannel = "#milla_alerts"
+alertChannel = ["#milla_alerts"]
eventTypes = ["PRIVMSG"]
fgColor = 0
bgColor = 28
[ircd.devinet.rss.manga]
rssFile = "/rssfeeds/manga.json"
-channel = "#manga"
+channel = ["#manga"]
[ircd.devinet.rss.anime]
rssFile = "/rssfeeds/anime.json"
-channel = "#anime"
+channel = ["#anime"]
[ircd.liberanet]
ircServer = "irc.libera.chat"
@@ -65,7 +65,7 @@ useTLS = true
disableSTSFallback = true
allowFlood = false
admins = ["noone_has_this_nick"]
-ircChannels = ["##milla1", "##milla2"]
+ircChannels = [["##milla1"], ["##milla2"]]
debug = true
out = true
ircProxy = "socks5://127.0.0.1:9051"
diff --git a/main.go b/main.go
index e2f7c7b..6d0d349 100644
--- a/main.go
+++ b/main.go
@@ -518,8 +518,11 @@ func runCommand(
break
}
-
- client.Cmd.Join(args[1])
+ if len(args) == 3 {
+ IrcJoin(client, []string{args[1], args[2]})
+ } else {
+ client.Cmd.Join(args[1])
+ }
case "leave":
if !isFromAdmin(appConfig.Admins, event) {
break
@@ -1165,7 +1168,7 @@ func connectToDB(appConfig *TomlConfig, ctx *context.Context, poolChan chan *pgx
log.Printf("%s connected to database", appConfig.IRCDName)
for _, channel := range appConfig.ScrapeChannels {
- tableName := getTableFromChanName(channel, appConfig.IRCDName)
+ tableName := getTableFromChanName(channel[0], appConfig.IRCDName)
query := fmt.Sprintf(
`create table if not exists %s (
id serial primary key,
@@ -1241,7 +1244,7 @@ func WatchListHandler(irc *girc.Client, appConfig TomlConfig) {
for _, channel := range watchlist.WatchList {
isRightEventType = false
- if channel == event.Params[0] {
+ if channel[0] == event.Params[0] {
for _, eventType := range watchlist.EventTypes {
if eventType == event.Command {
@@ -1268,7 +1271,7 @@ func WatchListHandler(irc *girc.Client, appConfig TomlConfig) {
"\x1b[0m" + event.Last()[indexes[0]+1+nextWhitespaceIndex:]
irc.Cmd.Message(
- watchlist.AlertChannel,
+ watchlist.AlertChannel[0],
fmt.Sprintf("%s: %s", watchname, rewrittenMessage))
log.Printf("matched from watchlist -- %s: %s", watchname, event.Last())
@@ -1356,7 +1359,7 @@ func runIRC(appConfig TomlConfig) {
irc.Handlers.AddBg(girc.CONNECTED, func(c *girc.Client, _ girc.Event) {
for _, channel := range appConfig.IrcChannels {
- c.Cmd.Join(channel)
+ IrcJoin(irc, channel)
}
})
@@ -1413,7 +1416,7 @@ func runIRC(appConfig TomlConfig) {
if len(appConfig.ScrapeChannels) > 0 {
irc.Handlers.AddBg(girc.CONNECTED, func(c *girc.Client, _ girc.Event) {
for _, channel := range appConfig.ScrapeChannels {
- c.Cmd.Join(channel)
+ IrcJoin(irc, channel)
}
})
@@ -1424,10 +1427,10 @@ func runIRC(appConfig TomlConfig) {
irc.Handlers.AddBg(girc.CONNECTED, func(client *girc.Client, _ girc.Event) {
for _, watchlist := range appConfig.WatchLists {
log.Print("joining ", watchlist.AlertChannel)
- client.Cmd.Join(watchlist.AlertChannel)
+ IrcJoin(irc, watchlist.AlertChannel)
for _, channel := range watchlist.WatchList {
- client.Cmd.Join(channel)
+ IrcJoin(irc, channel)
}
}
})
diff --git a/plugins.go b/plugins.go
index 0ffaba2..efde643 100644
--- a/plugins.go
+++ b/plugins.go
@@ -221,8 +221,13 @@ func registerLuaCommand(luaState *lua.LState, appConfig *TomlConfig) func(*lua.L
func ircJoinChannelClosure(luaState *lua.LState, client *girc.Client) func(*lua.LState) int {
return func(luaState *lua.LState) int {
channel := luaState.CheckString(1)
+ password := luaState.CheckString(2)
- client.Cmd.Join(channel)
+ if password != "" {
+ client.Cmd.JoinKey(channel, password)
+ } else {
+ client.Cmd.Join(channel)
+ }
return 0
}
diff --git a/rss.go b/rss.go
index 60a8066..2c34459 100644
--- a/rss.go
+++ b/rss.go
@@ -21,7 +21,8 @@ import (
func GetFeed(feed FeedConfig,
client *girc.Client,
pool *pgxpool.Pool,
- channel, groupName string,
+ channel []string,
+ groupName string,
) {
rowName := groupName + "__" + feed.Name + "__"
@@ -55,7 +56,7 @@ func GetFeed(feed FeedConfig,
for _, item := range parsedFeed.Items {
if item.PublishedParsed.Unix() > newestFromDB {
- client.Cmd.Message(channel, parsedFeed.Title+": "+item.Title+">>>"+item.Link)
+ client.Cmd.Message(channel[0], parsedFeed.Title+": "+item.Title+">>>"+item.Link)
}
}
@@ -77,7 +78,8 @@ func feedDispatcher(
config RSSConfig,
client *girc.Client,
pool *pgxpool.Pool,
- channel, groupName string,
+ channel []string,
+ groupName string,
period int,
) {
for {
@@ -164,7 +166,7 @@ func runRSS(appConfig *TomlConfig, client *girc.Client) {
for groupName, rss := range appConfig.Rss {
log.Print("RSS: joining ", rss.Channel)
- client.Cmd.Join(rss.Channel)
+ IrcJoin(client, rss.Channel)
rssConfig := ParseRSSConfig(rss.RssFile)
if rssConfig == nil {
log.Print("Could not parse RSS config file " + rss.RssFile + ". Exiting.")
diff --git a/types.go b/types.go
index b976840..7f1be93 100644
--- a/types.go
+++ b/types.go
@@ -32,13 +32,13 @@ type LuaLstates struct {
}
type WatchList struct {
- AlertChannel string `toml:"alertChannel"`
- WatchList []string `toml:"watchList"`
- WatchFiles []string `toml:"watchFiles"`
- Words []string `toml:"watchWords"`
- EventTypes []string `toml:"eventTypes"`
- FGColor int `toml:"fgColor"`
- BGColor int `toml:"bgColor"`
+ AlertChannel []string `toml:"alertChannel"`
+ WatchList [][]string `toml:"watchList"`
+ WatchFiles []string `toml:"watchFiles"`
+ Words []string `toml:"watchWords"`
+ EventTypes []string `toml:"eventTypes"`
+ FGColor int `toml:"fgColor"`
+ BGColor int `toml:"bgColor"`
}
type LuaCommand struct {
@@ -47,8 +47,8 @@ type LuaCommand struct {
}
type RssFile struct {
- RssFile string `toml:"rssFile"`
- Channel string `toml:"channel"`
+ RssFile string `toml:"rssFile"`
+ Channel []string `toml:"channel"`
}
type TomlConfig struct {
@@ -106,9 +106,9 @@ type TomlConfig struct {
Out bool `toml:"out"`
AdminOnly bool `toml:"adminOnly"`
pool *pgxpool.Pool
- Admins []string `toml:"admins"`
- IrcChannels []string `toml:"ircChannels"`
- ScrapeChannels []string `toml:"scrapeChannels"`
+ Admins []string `toml:"admins"`
+ IrcChannels [][]string `toml:"ircChannels"`
+ ScrapeChannels [][]string `toml:"scrapeChannels"`
}
func (config *TomlConfig) insertLState(
diff --git a/utils.go b/utils.go
new file mode 100644
index 0000000..81c2f70
--- /dev/null
+++ b/utils.go
@@ -0,0 +1,11 @@
+package main
+
+import "github.com/lrstanley/girc"
+
+func IrcJoin(irc *girc.Client, channel []string) {
+ if len(channel) >= 0 && channel[0] == "" {
+ irc.Cmd.JoinKey(channel[0], channel[1])
+ } else {
+ irc.Cmd.Join(channel[0])
+ }
+}