-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLetsGoTroet.go
64 lines (56 loc) · 1.37 KB
/
LetsGoTroet.go
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
package main
import (
"LetsGoTroet/app"
"LetsGoTroet/irc"
"LetsGoTroet/mastodon"
"database/sql"
"github.com/joho/godotenv"
_ "github.com/mattn/go-sqlite3"
"log"
"os"
)
const SQLITE_FILENAME = "messages.db"
func main() {
err := godotenv.Load(".env")
if err != nil {
log.Println("Did not load .env file")
}
// Get variables from environment
irchost := os.Getenv("IRC_HOST")
channel := os.Getenv("IRC_CHANNEL")
nick := os.Getenv("IRC_NICK")
nick_pw := os.Getenv("IRC_NICKPASS")
baseurl := os.Getenv("MASTODON_BASEURL")
username := os.Getenv("MASTODON_USERNAME")
password := os.Getenv("MASTODON_PASSWORD")
id := os.Getenv("MASTODON_ID")
secret := os.Getenv("MASTODON_SECRET")
access_token := os.Getenv("MASTODON_ACCESS_TOKEN")
// Setup database
db := setupDB(SQLITE_FILENAME)
// Setup IRC adapter
bot, err := irc.New(irchost, nick, channel, db)
if err != nil {
log.Println("IRC Adapter creation failed:", err)
return
}
if len(nick_pw) > 0 {
bot.SetPassword(nick_pw)
}
// Setup Mastodon adapter
mst, err := mastodon.New(baseurl, id, secret, access_token, username, password, db)
if err != nil {
log.Println(err)
return
}
// Run service
service := app.New(bot, mst)
service.Run()
}
func setupDB(filename string) *sql.DB {
db, err := sql.Open("sqlite3", filename)
if err != nil {
log.Fatal("Could not open database, Error:", err)
}
return db
}