Compare commits

..

No commits in common. 'develop' and 'master' have entirely different histories.

  1. 3
      .gitignore
  2. 40
      Makefile
  3. 1
      config.gcfg
  4. 8
      deps/Dockerfile
  5. 11
      deps/lorebot.service
  6. 44
      deps/manifest.json
  7. 4
      deps/redis.conf
  8. BIN
      deps/rootfs.tar.gz
  9. 7
      deps/run.sh
  10. 113
      lorebot/botfunc.go
  11. 410
      lorebot/lorebot.go
  12. 72
      readme.md

3
.gitignore vendored

@ -1,5 +1,4 @@
*.swp
*.aci
*.auth
bin/
stage.tmp/
.auth

40
Makefile

@ -5,9 +5,6 @@ IMAGE_NAME=smpldbot
all: lorebot
depends:
go get github.com/nlopes/slack
lorebot:
$(GOC) lorebot/lorebot.go
@ -25,7 +22,6 @@ docker: stat
cp bin/lorebot stage.tmp/
cp deps/rootfs.tar.gz stage.tmp/
cp deps/Dockerfile stage.tmp/
cp deps/redis.conf stage.tmp/
chmod +x deps/run.sh
cp deps/run.sh stage.tmp/
cp config.gcfg stage.tmp/
@ -33,42 +29,6 @@ docker: stat
sudo docker build -t $(IMAGE_NAME) .
@echo "$(IMAGE_NAME) built"
aci: stat
mkdir -p stage.tmp/lorebot-layout/rootfs/
tar -zxf deps/rootfs.tar.gz -C stage.tmp/lorebot-layout/rootfs/
cp bin/lorebot stage.tmp/lorebot-layout/rootfs/lorebot
chmod +x deps/run.sh
cp deps/run.sh stage.tmp/lorebot-layout/rootfs/
cp deps/redis.conf stage.tmp/lorebot-layout/rootfs/
cp config.gcfg stage.tmp/lorebot-layout/rootfs/
cp deps/manifest.json stage.tmp/lorebot-layout/manifest
cd stage.tmp/ && \
actool build lorebot-layout lorebot.aci && \
mv lorebot.aci ../
@echo "lorebot.aci built"
test_docker:
mkdir -p /tmp/lorebot/redis/
touch /tmp/lorebot/dump.rdb
cp .auth /tmp/lorebot/
sudo docker run \
-it \
-v /tmp/lorebot/redis:/redisbackup:rw \
-v /tmp/lorebot/.auth:/.auth:ro \
smpldbot
test_aci:
mkdir -p /tmp/lorebot/redis/
touch /tmp/lorebot/dump.rdb
cp .auth /tmp/lorebot/
sudo rkt run \
--volume redis,kind=host,source=/tmp/lorebot/redis/ \
--volume auth,kind=host,source=/tmp/lorebot/.auth \
--net=host \
--insecure-options=image \
./lorebot.aci
clean:
rm -rf bin/
rm -rf stage.tmp/
rm -rf lorebot.aci

1
config.gcfg

@ -1,6 +1,5 @@
[lorebot]
loglevel = "debug"
slackdebug = false
bootstrapdelay = 1
AuthFile = ".auth"

8
deps/Dockerfile vendored

@ -1,9 +1,7 @@
FROM scratch
FROM alpine
#RUN apk --update add ca-certificates redis
#RUN mkdir /redisbackup/
ADD rootfs.tar.gz /
COPY redis.conf /
RUN apk --update add ca-certificates redis
RUN mkdir /redisbackup/
COPY config.gcfg /
COPY lorebot /
COPY run.sh /

11
deps/lorebot.service vendored

@ -1,11 +0,0 @@
[Unit]
Description=automod of all lorez
[Service]
ExecStart=/usr/bin/rkt run \
--net=host \
--volume redis,kind=host,source=/tmp/dump.rdb \
unixvoid.com/smpldbot
[Install]
WantedBy=multi-user.target

44
deps/manifest.json vendored

@ -1,44 +0,0 @@
{
"acKind": "ImageManifest",
"acVersion": "0.7.1",
"name": "unixvoid.com/lorebot",
"labels": [
{
"name": "version",
"value": "latest"
},
{
"name": "arch",
"value": "amd64"
},
{
"name": "os",
"value": "linux"
}
],
"app": {
"user": "root",
"group": "root",
"exec": [
"/run.sh"
],
"mountPoints": [
{
"name": "redis",
"path": "/redisbackup/",
"readOnly": false
},
{
"name": "auth",
"path": "/.auth",
"readOnly": false
}
]
},
"annotations": [
{
"name": "authors",
"value": "Matthew Faltys <mfaltys@gmail.com>"
}
]
}

4
deps/redis.conf vendored

@ -1,4 +0,0 @@
daemonize yes
dbfilename dump.rdb
dir /redisbackup/
save 30 1

BIN
deps/rootfs.tar.gz vendored

Binary file not shown.

7
deps/run.sh vendored

@ -1,5 +1,10 @@
#!/bin/sh
redis-server /redis.conf
#echo "daemonize yes" > /redis.conf
echo "dbfilename dump.rdb" >> /redis.conf
echo "dir /redisbackup/" >> /redis.conf
echo "save 30 1" >> /redis.conf
redis-server /redis.conf &
/lorebot $@

113
lorebot/botfunc.go

@ -6,21 +6,21 @@ import (
"strings"
"time"
"github.com/unixvoid/glogger"
"gopkg.in/redis.v5"
)
func loreQuery(searchTerm string, redisClient *redis.Client) ([]string, error) {
val, err := redisClient.Sort(searchTerm, redis.Sort{Order: "ALPHA"}).Result()
func loreQuery(searchTerm string, redisClient *redis.Client) (string, error) {
val, err := redisClient.Get(searchTerm).Result()
if err != nil {
return nil, errors.New("String not found.")
return "", errors.New("String not found.")
} else {
return val, nil
}
}
func loreCheck(searchTerm, searchType string, redisClient *redis.Client) (string, error) {
val, err := redisClient.HGet(fmt.Sprintf("%s:%s", searchType, searchTerm), "content").Result()
searchString := fmt.Sprintf("%s:%s:%s", searchType, searchTerm, "content")
val, err := redisClient.Get(searchString).Result()
if err != nil {
return "", errors.New("String not found.")
} else {
@ -31,37 +31,29 @@ func loreCheck(searchTerm, searchType string, redisClient *redis.Client) (string
func loreNewString(nick, newString, newType string, redisClient *redis.Client) error {
s := strings.SplitN(newString, " ", 2)
command, content := s[0], []byte(s[1])
stripContent := strings.Replace(fmt.Sprintf("%s", content), "<", "", -1)
stripLinks := strings.Replace(stripContent, ">", "", -1)
// dont allow certain chars
if strings.ContainsAny(command, ";:,.'\"!$%^*()/\\") {
// reject user input, it has unwanted chars
return errors.New("error: entry contains unwanted characters")
}
t := time.Now()
// create a timestamp to use
cdate := t.Format("2006-01-02 15:04:05")
// set created date
attribute := "cdate"
date := t.Format("2006-01-02 15:04:05")
setstring := fmt.Sprintf("%s:%s:%s", newType, command, attribute)
redisClient.Set(setstring, date, 0)
// create the redis hash
_, err := redisClient.HMSet(fmt.Sprintf("%s:%s", newType, command), map[string]string{
"content": stripLinks,
"cdate": cdate,
"owner": nick,
}).Result()
if err != nil {
glogger.Error.Println("error setting redis hash")
return errors.New("error setting redis hash")
}
// set owner
attribute = "owner"
setstring = fmt.Sprintf("%s:%s:%s", newType, command, attribute)
redisClient.Set(setstring, nick, 0)
// add lore to index
err = redisClient.SAdd(fmt.Sprintf("index:%s:added", newType), command).Err()
if err != nil {
glogger.Error.Println("error updating redis index")
return errors.New("error updating redis index")
}
// set content
attribute = "content"
setstring = fmt.Sprintf("%s:%s:%s", newType, command, attribute)
redisClient.Set(setstring, content, 0)
// append to index
appendIndex := fmt.Sprintf("index:%s:added", newType)
appendString := fmt.Sprintf(" %s", command)
redisClient.Append(appendIndex, appendString)
return nil
}
@ -69,40 +61,43 @@ func loreNewString(nick, newString, newType string, redisClient *redis.Client) e
func loreRmString(nick, rmString, rmType string, redisClient *redis.Client) error {
t := time.Now()
// remove redis hash containing lore and metadata
redisClient.Del(fmt.Sprintf("%s:%s", rmType, rmString))
// create a timestamp to use
rmdate := t.Format("2006-01-02 15:04:05")
// create the redis hash
_, err := redisClient.HMSet(fmt.Sprintf("%s:%s", rmType, rmString), map[string]string{
"rmdate": rmdate,
"rmby": nick,
}).Result()
if err != nil {
glogger.Error.Println("error setting redis hash")
return errors.New("error setting redis hash")
}
// add lore to index
redisClient.SAdd(fmt.Sprintf("index:%s:removed", rmType), rmString).Err()
if err != nil {
glogger.Error.Printf("error removing lore from 'index:%s:removed'\n", rmType)
}
// remove lore form added index
redisClient.SRem(fmt.Sprintf("index:%s:added", rmType), rmString).Err()
if err != nil {
glogger.Error.Printf("error removing lore from 'index:%s:added'\n", rmType)
}
// remove content
keyString := fmt.Sprintf("%s:%s:%s", rmType, rmString, "content")
redisClient.Del(keyString)
//redisClient.Set(keyString, "--LORE HAS BEEN REMOVED--", 0)
// set "removed by"
attribute := "rmby"
setstring := fmt.Sprintf("%s:%s:%s", rmType, rmString, attribute)
redisClient.Set(setstring, nick, 0)
// set removed date
attribute = "rmdate"
date := t.Format("2006-01-02 15:04:05")
setstring = fmt.Sprintf("%s:%s:%s", rmType, rmString, attribute)
redisClient.Set(setstring, date, 0)
// append to deleted index
appendIndex := fmt.Sprintf("index:%s:removed", rmType)
appendString := fmt.Sprintf(" %s", rmString)
redisClient.Append(appendIndex, appendString)
// remove from added index
queryString := fmt.Sprintf("index:%s:added", rmType)
tmpIndex, _ := loreQuery(queryString, redisClient)
// add a space to the beginning of string to replace
formattedString := fmt.Sprintf(" %s ", rmString)
// find and replace
newIndex := strings.Replace(tmpIndex, formattedString, " ", -1)
redisClient.Set(queryString, newIndex, 0)
return nil
}
func loreAttrQuery(queryString, queryType, queryAttr string, redisClient *redis.Client) (string, error) {
val, err := redisClient.HGet(fmt.Sprintf("%s:%s", queryType, queryAttr), queryString).Result()
searchString := fmt.Sprintf("%s:%s:%s", queryType, queryAttr, queryString)
val, err := redisClient.Get(searchString).Result()
if err != nil {
return "", errors.New("String not found.")
} else {

410
lorebot/lorebot.go

@ -5,12 +5,10 @@ import (
"fmt"
"io"
"io/ioutil"
"math/rand"
"mime/multipart"
"net/http"
"net/textproto"
"os"
"strconv"
"strings"
"time"
@ -23,7 +21,6 @@ import (
type Config struct {
Lorebot struct {
Loglevel string
SlackDebug bool
BootstrapDelay time.Duration
AuthFile string
}
@ -64,6 +61,7 @@ func main() {
auth := lines[0]
api := slack.New(auth)
//api.SetDebug(true)
rtm := api.NewRTM()
go rtm.ManageConnection()
@ -158,40 +156,16 @@ func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *
contenthandler(rtm, ev, s[1], "lore", redisClient)
case "newlore":
if strings.Contains(content, " ") {
newhandler(rtm, ev, content, "lore", redisClient)
} else {
rtm.SendMessage(rtm.NewOutgoingMessage("not proper syntax", ev.Channel))
return
}
case "newdubs":
s := strings.SplitN(string(ev.Text), " ", 2)
newdubshandler(rtm, ev, s[1], redisClient)
case "rmdubs":
s := strings.SplitN(string(ev.Text), " ", 2)
rmdubshandler(rtm, ev, s[1], redisClient)
case "newlunch":
s := strings.SplitN(string(ev.Text), " ", 2)
newlunchhandler(rtm, ev, s[1], redisClient)
case "rmlunch":
s := strings.SplitN(string(ev.Text), " ", 2)
rmlunchhandler(rtm, ev, s[1], redisClient)
case "newbrb":
s := strings.SplitN(string(ev.Text), " ", 2)
newbrbhandler(rtm, ev, s[1], redisClient)
case "rmbrb":
s := strings.SplitN(string(ev.Text), " ", 2)
rmbrbhandler(rtm, ev, s[1], redisClient)
newhandler(rtm, ev, content, "lore", redisClient)
case "rmlore":
rmhandler(rtm, ev, content, "lore", redisClient)
case "rek":
s := strings.SplitN(string(ev.Text), " ", 2)
rekhandler(rtm, ev, s[1], redisClient)
case "rip":
s := strings.SplitN(string(ev.Text), " ", 2)
riphandler(rtm, ev, s[1])
case "summon":
s := strings.SplitN(string(ev.Text), " ", 2)
summonhandler(rtm, ev, s[1])
case "gnu":
s := strings.SplitN(string(ev.Text), " ", 2)
gnuhandler(rtm, ev, s[1])
@ -217,29 +191,9 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r
case "help2":
advancedhelpmsg(rtm, ev)
case "rng":
rnghandler(rtm, ev, redisClient)
case "egg":
egghandler(rtm, ev, redisClient)
case "giveup":
giveuphandler(rtm, ev, redisClient)
case "depricatedrng":
depricatedrnghandler(rtm, ev, redisClient)
case "dubs":
dubshandler(rtm, ev, redisClient)
case "lunch":
lunchhandler(rtm, ev, redisClient)
case "brb":
brbhandler(rtm, ev, redisClient)
case "roll":
rollhandler(rtm, ev)
case "rr":
rrhandler(rtm, ev)
case "dice":
dicerollhandler(rtm, ev)
case "ceelo":
ceelorollhandler(rtm, ev)
case "listen":
rtm.SendMessage(rtm.NewOutgoingMessage("*it's what you hearin*", ev.Channel))
rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel))
case "version":
rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel))
case "lorelist":
listhandler(redisClient, rtm, ev, "lore", "added")
case "removedlore":
@ -251,20 +205,6 @@ func staticCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *r
case "lorestatus":
lorestatus(rtm, ev, redisClient)
}
// get that dice handler
if len(ev.Text) >= 2 {
if strings.Contains(ev.Text, ".d") {
trm := strings.Replace(ev.Text, ".d", "", -1)
// check if the rest of the string is an int
num, err := strconv.Atoi(trm)
if err == nil {
//glogger.Debug.Printf("rolling for %d", num)
dhandler(rtm, ev, num)
}
}
}
}
func helpmsg(rtm *slack.RTM, ev *slack.MessageEvent) {
@ -293,7 +233,8 @@ func advancedhelpmsg(rtm *slack.RTM, ev *slack.MessageEvent) {
func contenthandler(rtm *slack.RTM, ev *slack.MessageEvent, message, queryType string, redisClient *redis.Client) {
loreTerm := strings.Replace(message, ".lore", "", -1)
glogger.Debug.Printf("searching for: %s\n", loreTerm)
println("searching for:", loreTerm)
//rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("searching for '%s'\n", loreTerm), ev.Channel))
content, err := loreCheck(loreTerm, queryType, redisClient)
if err == nil {
@ -320,179 +261,6 @@ func rekhandler(rtm *slack.RTM, ev *slack.MessageEvent, target string, redisClie
rtm.SendMessage(rtm.NewOutgoingMessage(rekFmt, ev.Channel))
}
func summonhandler(rtm *slack.RTM, ev *slack.MessageEvent, target string) {
sumFmt := fmt.Sprintf("つ◕_◕)つ %s つ◕_◕)つ", target)
rtm.SendMessage(rtm.NewOutgoingMessage(sumFmt, ev.Channel))
}
func riphandler(rtm *slack.RTM, ev *slack.MessageEvent, target string) {
// create a timestamp to use
t := time.Now()
tstamp := t.Format("01-02-2006")
ripFmt := fmt.Sprintf("here lies %s, disrespected to death %s..", target, tstamp)
rtm.SendMessage(rtm.NewOutgoingMessage(ripFmt, ev.Channel))
}
func rollhandler(rtm *slack.RTM, ev *slack.MessageEvent) {
//fmt.Print(rand.Intn(100))
rndStr := fmt.Sprintf("%08d", rand.Int63n(1e8))
rtm.SendMessage(rtm.NewOutgoingMessage(rndStr, ev.Channel))
}
func dicerollhandler(rtm *slack.RTM, ev *slack.MessageEvent) {
//fmt.Print(rand.Intn(100))
rand.Seed(time.Now().UnixNano())
rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("%d", rand.Intn(6)+1), ev.Channel))
}
func ceelorollhandler(rtm *slack.RTM, ev *slack.MessageEvent) {
rand.Seed(time.Now().UnixNano())
// set condition
hand := false
for !hand {
roll0 := rand.Intn(6) + 1
roll1 := rand.Intn(6) + 1
roll2 := rand.Intn(6) + 1
rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("%d, %d, %d", roll0, roll1, roll2), ev.Channel))
// check for pair
if (roll0 == roll1) || (roll0 == roll2) || (roll1 == roll2) {
hand = true
}
a := fmt.Sprintf("%d%d%d", roll0, roll1, roll2)
// check for instant win
if strings.Contains(a, "4") && strings.Contains(a, "5") && strings.Contains(a, "6") {
hand = true
}
// check for instant loss
if strings.Contains(a, "1") && strings.Contains(a, "2") && strings.Contains(a, "3") {
hand = true
}
time.Sleep(1000 * time.Millisecond)
}
}
func rrhandler(rtm *slack.RTM, ev *slack.MessageEvent) {
//fmt.Print(rand.Intn(100))
dice := []string{"*click*", "*BANG*", "*click*", "*click*", "*click*", "*click*"}
rand.Seed(time.Now().UnixNano())
rndStr := dice[rand.Intn(len(dice)-1)]
rtm.SendMessage(rtm.NewOutgoingMessage(rndStr, ev.Channel))
}
func dhandler(rtm *slack.RTM, ev *slack.MessageEvent, num int) {
if (num > 0) && (num < 99999999) {
rand.Seed(time.Now().UnixNano())
rtm.SendMessage(rtm.NewOutgoingMessage(fmt.Sprintf("%d", rand.Intn(num)+1), ev.Channel))
} else {
rtm.SendMessage(rtm.NewOutgoingMessage("na fam, we need a different number. stay lit tho", ev.Channel))
}
}
func depricatedrnghandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) {
// get random lore from list
rngLore, err := redisClient.SRandMember("index:lore:added").Result()
if err != nil {
fmt.Printf("%v\n", err)
}
// get lore content
rngContent, err := loreCheck(rngLore, "lore", redisClient)
if err != nil {
fmt.Printf("%v\n", err)
rtm.SendMessage(rtm.NewOutgoingMessage("beep boop.. broken bot..", ev.Channel))
return
}
rngMsg := fmt.Sprintf("Random lore: `%s`\n%s", rngLore, rngContent)
rtm.SendMessage(rtm.NewOutgoingMessage(rngMsg, ev.Channel))
}
func rnghandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) {
// aka index:command:added
newType := fmt.Sprintf("index:lore:added")
//command, err := botfunc.Query(newType, redisClient)
command, err := loreQuery(newType, redisClient)
if err != nil {
glogger.Error.Println(err)
println(err)
}
// if the array is empty, exit early
if len(command) <= 0 {
return
}
// pick a random one
rand.Seed(time.Now().UnixNano())
rngLore := fmt.Sprint(command[rand.Intn(len(command))])
glogger.Debug.Printf("rng lore: %s\n", rngLore)
// get lore content
rngContent, err := loreCheck(rngLore, "lore", redisClient)
if err != nil {
glogger.Error.Printf("%v\n", err)
rtm.SendMessage(rtm.NewOutgoingMessage("beep boop.. broken bot..", ev.Channel))
return
}
glogger.Debug.Printf("rng content: %s\n", rngContent)
rngMsg := fmt.Sprintf("Random lore: `%s`\n%s", rngLore, rngContent)
rtm.SendMessage(rtm.NewOutgoingMessage(rngMsg, ev.Channel))
}
func egghandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) {
// aka index:command:added
newType := fmt.Sprintf("index:lore:added")
//command, err := botfunc.Query(newType, redisClient)
command, err := loreQuery(newType, redisClient)
if err != nil {
glogger.Error.Println(err)
println(err)
}
// if the array is empty, exit early
if len(command) <= 0 {
return
}
// pick a random one
rand.Seed(time.Now().UnixNano())
rngLore := fmt.Sprint(command[rand.Intn(len(command))])
println(rngLore)
// get lore content
rngContent, err := loreCheck(rngLore, "lore", redisClient)
if err != nil {
fmt.Printf("%v\n", err)
rtm.SendMessage(rtm.NewOutgoingMessage("beep boop.. broken bot..", ev.Channel))
return
}
// set the lore in case we cant find it.
redisClient.Del("index:egg")
err = redisClient.Set("index:egg", rngLore, 0).Err()
if err != nil {
glogger.Error.Println("error updating redis egg index")
}
rngMsg := fmt.Sprintf("begin the hunt boiiz...\n ```%s```", rngContent)
rtm.SendMessage(rtm.NewOutgoingMessage(rngMsg, ev.Channel))
}
func giveuphandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) {
giveup, err := redisClient.Get("index:egg").Result()
if err != nil {
glogger.Error.Println("error getting redis egg index")
glogger.Error.Println(err)
}
giveupMsg := fmt.Sprintf("foolz.. it was `%s`", giveup)
rtm.SendMessage(rtm.NewOutgoingMessage(giveupMsg, ev.Channel))
}
func gnuhandler(rtm *slack.RTM, ev *slack.MessageEvent, target string) {
gnuFmt := fmt.Sprintf("slaps the nonfree software out of %s's hands", target)
rtm.SendMessage(rtm.NewOutgoingMessage(gnuFmt, ev.Channel))
@ -507,7 +275,8 @@ func listhandler(redisClient *redis.Client, rtm *slack.RTM, ev *slack.MessageEve
glogger.Error.Println(err)
println(err)
}
fCommand := strings.Join(command, "\n")
fCommand := strings.Replace(command, " ", "\n", -1)
fCommand = strings.Replace(fCommand, "\n", "", 1)
// initialize buffer
bodyBuf := &bytes.Buffer{}
@ -545,8 +314,8 @@ func listhandler(redisClient *redis.Client, rtm *slack.RTM, ev *slack.MessageEve
func lorestatus(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) {
command, _ := loreQuery("index:lore:added", redisClient)
loreammount := len(command)
status := fmt.Sprintf("the lore db has %d entries", loreammount)
loreammount := strings.Count(command, " ")
status := fmt.Sprintf("the lore db has %d entries", loreammount-1)
rtm.SendMessage(rtm.NewOutgoingMessage(status, ev.Channel))
}
@ -567,163 +336,6 @@ func newhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, newType string,
}
}
func newdubshandler(rtm *slack.RTM, ev *slack.MessageEvent, newContent string, redisClient *redis.Client) {
// prep content for dubsification
// aka remove the '<' and '>' that slack adds
newContent = strings.Replace(newContent, "<", "", -1)
newContent = strings.Replace(newContent, ">", "", -1)
err := redisClient.SAdd("index:dubs", newContent)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("dubs checked", ev.Channel))
} else {
rtm.SendMessage(rtm.NewOutgoingMessage("dubs check failed", ev.Channel))
}
}
func rmdubshandler(rtm *slack.RTM, ev *slack.MessageEvent, rmContent string, redisClient *redis.Client) {
// prep content for dubs removal
// aka remove the '<' and '>' that slack adds
rmContent = strings.Replace(rmContent, "<", "", -1)
rmContent = strings.Replace(rmContent, ">", "", -1)
err := redisClient.SRem("index:dubs", rmContent)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("dubs unchecked", ev.Channel))
} else {
rtm.SendMessage(rtm.NewOutgoingMessage("dubs check failed", ev.Channel))
}
}
func dubshandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) {
// aka index:command:added
newType := fmt.Sprintf("index:dubs")
command, err := loreQuery(newType, redisClient)
if err != nil {
glogger.Error.Println(err)
}
// if the array is empty, exit early
if len(command) <= 0 {
return
}
// pick a random one
rand.Seed(time.Now().UnixNano())
rngDubs := fmt.Sprint(command[rand.Intn(len(command))])
rtm.SendMessage(rtm.NewOutgoingMessage(rngDubs, ev.Channel))
// roll after we've proccessed dubs
// you already know tho..
//re := regexp.MustCompile(`taylor|swift|2725225`)
//if re.MatchString(rngDubs) {
// rndInt := 1 + rand.Intn(10-1)
// rndStr := fmt.Sprintf("%06d", rand.Int63n(1e6))
// finStr := fmt.Sprintf("%s%d%d", rndStr, rndInt, rndInt)
// rtm.SendMessage(rtm.NewOutgoingMessage(finStr, ev.Channel))
//} else {
// rollhandler(rtm, ev)
//}
rollhandler(rtm, ev)
}
func newlunchhandler(rtm *slack.RTM, ev *slack.MessageEvent, newContent string, redisClient *redis.Client) {
// prep content for lunchification
// aka remove the '<' and '>' that slack adds
newContent = strings.Replace(newContent, "<", "", -1)
newContent = strings.Replace(newContent, ">", "", -1)
err := redisClient.SAdd("index:lunch", newContent)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("lunch location added", ev.Channel))
} else {
rtm.SendMessage(rtm.NewOutgoingMessage("lunch location addition failed", ev.Channel))
}
}
func rmlunchhandler(rtm *slack.RTM, ev *slack.MessageEvent, rmContent string, redisClient *redis.Client) {
// prep content for lunch removal
// aka remove the '<' and '>' that slack adds
rmContent = strings.Replace(rmContent, "<", "", -1)
rmContent = strings.Replace(rmContent, ">", "", -1)
err := redisClient.SRem("index:lunch", rmContent)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("lunch location removed", ev.Channel))
} else {
rtm.SendMessage(rtm.NewOutgoingMessage("lunch location removal failed", ev.Channel))
}
}
func lunchhandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) {
// aka index:command:added
newType := fmt.Sprintf("index:lunch")
command, err := loreQuery(newType, redisClient)
if err != nil {
glogger.Error.Println(err)
}
// if the array is empty, exit early
if len(command) <= 0 {
return
}
// pick a random one
rand.Seed(time.Now().UnixNano())
rngDubs := fmt.Sprint(command[rand.Intn(len(command))])
rtm.SendMessage(rtm.NewOutgoingMessage(rngDubs, ev.Channel))
}
func newbrbhandler(rtm *slack.RTM, ev *slack.MessageEvent, newContent string, redisClient *redis.Client) {
// prep content for brbification
// aka remove the '<' and '>' that slack adds
newContent = strings.Replace(newContent, "<", "", -1)
newContent = strings.Replace(newContent, ">", "", -1)
err := redisClient.SAdd("index:brb", newContent)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("tjancism added", ev.Channel))
} else {
rtm.SendMessage(rtm.NewOutgoingMessage("tjanceism addition failed", ev.Channel))
}
}
func rmbrbhandler(rtm *slack.RTM, ev *slack.MessageEvent, rmContent string, redisClient *redis.Client) {
// prep content for brb removal
// aka remove the '<' and '>' that slack adds
rmContent = strings.Replace(rmContent, "<", "", -1)
rmContent = strings.Replace(rmContent, ">", "", -1)
err := redisClient.SRem("index:brb", rmContent)
if err != nil {
rtm.SendMessage(rtm.NewOutgoingMessage("tjancism removed", ev.Channel))
} else {
rtm.SendMessage(rtm.NewOutgoingMessage("tjancism removal failed", ev.Channel))
}
}
func brbhandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *redis.Client) {
// aka index:command:added
newType := fmt.Sprintf("index:brb")
command, err := loreQuery(newType, redisClient)
if err != nil {
glogger.Error.Println(err)
}
// if the array is empty, exit early
if len(command) <= 0 {
return
}
// pick a random one
rand.Seed(time.Now().UnixNano())
rngDubs := fmt.Sprint(command[rand.Intn(len(command))])
rtm.SendMessage(rtm.NewOutgoingMessage(rngDubs, ev.Channel))
}
func rmhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, rmType string, redisClient *redis.Client) {
// get nick from slack api
user, err := rtm.GetUserInfo(ev.User)

72
readme.md

@ -1,72 +0,0 @@
# Lorebot
This is the bot running over at the sampled slack.
## Commands
### 2 parameters
* `lore`: get a specific lore
* `rip`: rest in piece a target
* `summon`: summon the specified target
* `gnu`: educate the target on freedoms
* `newdubs`: add a new dubs image
* `rmdubs`: remove an existing dubs image
* `created`: lookup when lore was created (some old lore wont have this field)
* `owner`: lookup who created a lore (some old lore wont have this field)
* `removedby`: lookup who removed a lore
* `removed`: lookup when lore was removed
### 1 parameter
* `help`: display help message 1
* `help2`: display help message 2
* `rng`: display random lore with the new rng algorithm
* `depricatedrng`: select random lore with the old rng algorithm
* `roll`: generate a random 8 digit integer
* `d20`: roll a 20 sided die
* `rr`: play russian roulette
* `dice`: roll a 6 sided die
* `dubs`: pick a random 'dubs checkum' image and roll
* `listen`: its what you hearin
* `lorelist`: generate a list of all lore
* `removedlore`: generate a list of removed lore
* `lorestatus`: display the number of active lore
## Building
This project makes use of the `make` command. The following commands are supported.
* `all`: dynamically compiles/builds the bot. outputs binary file to `bin/`
* `run`: runs the bot
* `stat`: statically compiles/builds the bot. outputs binary file to `bin/`
* `docker`: builds a docker image
* `aci`: builds an ACI image
* `test_docker`: tests the docker image
* `test_aci`: tests the ACI image
* `clean`: cleans the project directory of any temp files
## Configuration
This bot takes advantage of the gcfg configuration which follows the INI
syntax.
`config.gcfg`
```
[lorebot]
loglevel = "debug"
slackdebug = false
bootstrapdelay = 1
AuthFile = ".auth"
[redis]
host = "127.0.0.1:6379"
password = ""
```
* `loglevel`: loglevel for the app (debug/info/error)
* `slackdebug`: wheather or not to show slacks API debugging
* `bootstrapdeplay`: number in seconds to delay binding the bot to redis (useful in containers)
* `AuthFile`: name/location of file containing the slack key
* `host`: location of the redis server
* `password`: password of the redis server
`.auth`
```
xoxb-86456556-IJDJksfkejsjdfj
```
this is a key generated by slack for the bot
Loading…
Cancel
Save