add systemd service files
collect configiguration together update README
This commit is contained in:
11
README.md
11
README.md
@@ -2,6 +2,17 @@
|
|||||||
- libxml2-dev libonig-dev
|
- libxml2-dev libonig-dev
|
||||||
- chrome / chromium browser
|
- chrome / chromium browser
|
||||||
|
|
||||||
|
# Install
|
||||||
|
|
||||||
|
```sh
|
||||||
|
go build .
|
||||||
|
mv fbBot /usr/local/bin/
|
||||||
|
cp contrib/etc /
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable fbBot.service
|
||||||
|
systemctl start fbBot.service
|
||||||
|
```
|
||||||
|
|
||||||
# Config
|
# Config
|
||||||
|
|
||||||
The Config File `config.yaml` should be located in /etc/fbbot.
|
The Config File `config.yaml` should be located in /etc/fbbot.
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import (
|
|||||||
func SetupCloseHandler() {
|
func SetupCloseHandler() {
|
||||||
c := make(chan os.Signal, 2)
|
c := make(chan os.Signal, 2)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGHUP)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGKILL)
|
||||||
go func() {
|
go func() {
|
||||||
<-c
|
<-c
|
||||||
fmt.Println("\r- Ctrl+C pressed in Terminal")
|
fmt.Println("\r- Ctrl+C pressed in Terminal")
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/chromedp/cdproto/cdp"
|
"github.com/chromedp/cdproto/cdp"
|
||||||
|
"github.com/robfig/cron/v3"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,6 +13,37 @@ const (
|
|||||||
passwordField = `//*[@id="m_login_password"]`
|
passwordField = `//*[@id="m_login_password"]`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// xPath constants
|
||||||
|
const (
|
||||||
|
xPathArticle string = `(//*/article[contains(concat(" ", normalize-space(@class)," "), " _55wo ") and contains(concat(" ", normalize-space(@class)," "), " _5rgr ")])[1]`
|
||||||
|
xPathArticleContent string = xPathArticle + `/div/div[contains(concat(" ", normalize-space(@class)," "), " _5rgt ") and contains(concat(" ", normalize-space(@class)," "), " _5nk5 ")]/span`
|
||||||
|
xPathImageURL string = xPathArticle + `/div/div[2]/div[1]/a/div/div/i`
|
||||||
|
xPathImageURL2 string = xPathArticle + `/div/div[2]/section/div/i`
|
||||||
|
xPathImageURL3 string = xPathArticle + `/div/div[2]/section/div/div/i` // Video Preview
|
||||||
|
xPathGiftURL string = xPathArticle + `/div/div[2]/section/a`
|
||||||
|
xPathPostingURL string = xPathArticle + `/div/header/div[2]/div/div/div[1]/div/a`
|
||||||
|
)
|
||||||
|
|
||||||
|
// internal URL constants
|
||||||
|
const (
|
||||||
|
fbPageURL string = "https://www.facebook.com/herowarsgame/"
|
||||||
|
// fbGameURL for search on expaned urls
|
||||||
|
fbGameURL string = "apps.facebook.com/mobaheroes"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Constants for all search for title of the Postings
|
||||||
|
const (
|
||||||
|
FreeTitanArtifact string = "FREE Titan Artifact"
|
||||||
|
FreeSilverCaskets string = "FREE Silver Caskets"
|
||||||
|
FreeSoulStones string = "Soul Stones"
|
||||||
|
FreeSkinStones string = "Skin Stones"
|
||||||
|
ActionKeepTheAmount string = "Keep the amount"
|
||||||
|
FreeWinterfestBaubles string = "Winterfest Baubles"
|
||||||
|
FreeTopFanPackage string = "Top Fan"
|
||||||
|
FreeEnergyForFee string = "ENERGY FOR FREE"
|
||||||
|
WinterfestRankingRewards string = "Winterfest ranking rewards"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
headers = map[string]interface{}{
|
headers = map[string]interface{}{
|
||||||
"Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
|
"Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
|
||||||
@@ -17,4 +51,12 @@ var (
|
|||||||
nodes []*cdp.Node
|
nodes []*cdp.Node
|
||||||
|
|
||||||
randomText = viper.GetStringSlice("comment_on_posts")
|
randomText = viper.GetStringSlice("comment_on_posts")
|
||||||
|
|
||||||
|
dataFT *DataFT
|
||||||
|
|
||||||
|
lastUpdatePosted string
|
||||||
|
regexStyleImage = regexp.MustCompile(`(?m)url\((.*)\);`)
|
||||||
|
|
||||||
|
// cronJob the Cronjob data
|
||||||
|
cronJob *cron.Cron
|
||||||
)
|
)
|
||||||
|
|||||||
13
contrib/etc/systemd/system/fbBot.service
Normal file
13
contrib/etc/systemd/system/fbBot.service
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=HW FB Bot service
|
||||||
|
After=network.target
|
||||||
|
StartLimitIntervalSec=0
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=always
|
||||||
|
RestartSec=1
|
||||||
|
ExecStart=/usr/local/bin/fbBot
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
43
facebook.go
43
facebook.go
@@ -5,7 +5,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"html"
|
"html"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -17,48 +16,6 @@ import (
|
|||||||
"mvdan.cc/xurls/v2"
|
"mvdan.cc/xurls/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// xPath constants
|
|
||||||
const (
|
|
||||||
xPathArticle string = `(//*/article[contains(concat(" ", normalize-space(@class)," "), " _55wo ") and contains(concat(" ", normalize-space(@class)," "), " _5rgr ")])[1]`
|
|
||||||
xPathArticleContent string = xPathArticle + `/div/div[contains(concat(" ", normalize-space(@class)," "), " _5rgt ") and contains(concat(" ", normalize-space(@class)," "), " _5nk5 ")]/span`
|
|
||||||
xPathImageURL string = xPathArticle + `/div/div[2]/div[1]/a/div/div/i`
|
|
||||||
xPathImageURL2 string = xPathArticle + `/div/div[2]/section/div/i`
|
|
||||||
xPathImageURL3 string = xPathArticle + `/div/div[2]/section/div/div/i` // Video Preview
|
|
||||||
xPathGiftURL string = xPathArticle + `/div/div[2]/section/a`
|
|
||||||
xPathPostingURL string = xPathArticle + `/div/header/div[2]/div/div/div[1]/div/a`
|
|
||||||
)
|
|
||||||
|
|
||||||
// internal URL constants
|
|
||||||
const (
|
|
||||||
fbPageURL string = "https://www.facebook.com/herowarsgame/"
|
|
||||||
webhookLive string = "https://discordapp.com/api/webhooks/..."
|
|
||||||
webhookLiveExcelsior string = "https://discordapp.com/api/webhooks/..."
|
|
||||||
webhookDev string = "https://discordapp.com/api/webhooks/..."
|
|
||||||
|
|
||||||
// fbGameURL for search on expaned urls
|
|
||||||
fbGameURL string = "apps.facebook.com/mobaheroes"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
dataFT *DataFT
|
|
||||||
|
|
||||||
lastUpdatePosted string
|
|
||||||
regexStyleImage = regexp.MustCompile(`(?m)url\((.*)\);`)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Constants for all search for title of the Postings
|
|
||||||
const (
|
|
||||||
FreeTitanArtifact string = "FREE Titan Artifact"
|
|
||||||
FreeSilverCaskets string = "FREE Silver Caskets"
|
|
||||||
FreeSoulStones string = "Soul Stones"
|
|
||||||
FreeSkinStones string = "Skin Stones"
|
|
||||||
ActionKeepTheAmount string = "Keep the amount"
|
|
||||||
FreeWinterfestBaubles string = "Winterfest Baubles"
|
|
||||||
FreeTopFanPackage string = "Top Fan"
|
|
||||||
FreeEnergyForFee string = "ENERGY FOR FREE"
|
|
||||||
WinterfestRankingRewards string = "Winterfest ranking rewards"
|
|
||||||
)
|
|
||||||
|
|
||||||
//FBPostData FBPostData
|
//FBPostData FBPostData
|
||||||
type FBPostData struct {
|
type FBPostData struct {
|
||||||
PostURL string
|
PostURL string
|
||||||
|
|||||||
5
main.go
5
main.go
@@ -17,11 +17,6 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// GlobalApp holds a pointer for the App
|
|
||||||
cronJob *cron.Cron
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
viper.SetDefault("development_mode", true)
|
viper.SetDefault("development_mode", true)
|
||||||
viper.SetDefault("cronjob_interval", "@every 5m")
|
viper.SetDefault("cronjob_interval", "@every 5m")
|
||||||
|
|||||||
Reference in New Issue
Block a user