Compare commits
No commits in common. "master" and "v5.0.1" have entirely different histories.
7 changed files with 3 additions and 400 deletions
|
@ -1,10 +1,5 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 5.1.0 - 2020-03-18
|
|
||||||
### Added
|
|
||||||
- PetCat twitch chat handler
|
|
||||||
- DailyEmote twitch chat handler
|
|
||||||
|
|
||||||
## 5.0.1 - 2020-03-08
|
## 5.0.1 - 2020-03-08
|
||||||
### Changed
|
### Changed
|
||||||
- Updated `go-twitch-irc` lib to v2.2.2
|
- Updated `go-twitch-irc` lib to v2.2.2
|
||||||
|
|
4
main.go
4
main.go
|
@ -8,7 +8,6 @@ import (
|
||||||
|
|
||||||
"galched-bot/modules/discord"
|
"galched-bot/modules/discord"
|
||||||
"galched-bot/modules/grace"
|
"galched-bot/modules/grace"
|
||||||
"galched-bot/modules/patpet"
|
|
||||||
"galched-bot/modules/settings"
|
"galched-bot/modules/settings"
|
||||||
"galched-bot/modules/subday"
|
"galched-bot/modules/subday"
|
||||||
"galched-bot/modules/twitchat"
|
"galched-bot/modules/twitchat"
|
||||||
|
@ -88,8 +87,7 @@ func main() {
|
||||||
var err error
|
var err error
|
||||||
app := fx.New(
|
app := fx.New(
|
||||||
fx.Logger(new(silentPrinter)),
|
fx.Logger(new(silentPrinter)),
|
||||||
fx.Provide(settings.New, grace.New, discord.New, subday.New,
|
fx.Provide(settings.New, grace.New, discord.New, subday.New, twitchat.New, web.New, youtube.New),
|
||||||
twitchat.New, web.New, youtube.New, patpet.New),
|
|
||||||
fx.Invoke(start))
|
fx.Invoke(start))
|
||||||
|
|
||||||
err = app.Start(context.Background())
|
err = app.Start(context.Background())
|
||||||
|
|
|
@ -1,88 +0,0 @@
|
||||||
package patpet
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"galched-bot/modules/settings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
Pet struct {
|
|
||||||
sync.RWMutex
|
|
||||||
path string
|
|
||||||
counter int
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func New(s *settings.Settings) (*Pet, error) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
counter int
|
|
||||||
)
|
|
||||||
|
|
||||||
petData, err := ioutil.ReadFile(s.PetDataPath)
|
|
||||||
if err != nil {
|
|
||||||
log.Print("pet: cannot read data file", err)
|
|
||||||
log.Print("pet: creating new counter")
|
|
||||||
} else {
|
|
||||||
err = json.Unmarshal(petData, &counter)
|
|
||||||
if err != nil {
|
|
||||||
counter = 0
|
|
||||||
log.Print("pet: cannot unmarshal data file", err)
|
|
||||||
log.Print("pet: creating new counter")
|
|
||||||
} else {
|
|
||||||
log.Print("pet: using previously saved counter")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Pet{
|
|
||||||
RWMutex: sync.RWMutex{},
|
|
||||||
path: s.PetDataPath,
|
|
||||||
counter: counter,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pet) Pet() int {
|
|
||||||
p.Lock()
|
|
||||||
defer p.Unlock()
|
|
||||||
|
|
||||||
p.counter++
|
|
||||||
return p.counter
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pet) Counter() int {
|
|
||||||
p.RUnlock()
|
|
||||||
defer p.RUnlock()
|
|
||||||
|
|
||||||
return p.counter
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Pet) Dump() {
|
|
||||||
p.RLock()
|
|
||||||
defer p.RUnlock()
|
|
||||||
|
|
||||||
data, err := json.Marshal(p.counter)
|
|
||||||
if err != nil {
|
|
||||||
log.Print("pet: cannot marshal counter", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
file, err := os.Create(p.path)
|
|
||||||
if err != nil {
|
|
||||||
log.Print("pet: cannot open counter file", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = fmt.Fprintf(file, string(data))
|
|
||||||
if err != nil {
|
|
||||||
log.Print("pet: cannot write to counter file")
|
|
||||||
}
|
|
||||||
err = file.Close()
|
|
||||||
if err != nil {
|
|
||||||
log.Print("pet: cannot close counter file")
|
|
||||||
}
|
|
||||||
log.Print("pet: counter dumped to file:", p.counter)
|
|
||||||
}
|
|
|
@ -8,13 +8,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "5.1.0"
|
version = "5.0.1"
|
||||||
twitchUser = "galchedbot"
|
twitchUser = "galchedbot"
|
||||||
twitchIRCRoom = "galched"
|
twitchIRCRoom = "galched"
|
||||||
discordTokenPath = "./tokens/.discordtoken"
|
discordTokenPath = "./tokens/.discordtoken"
|
||||||
twitchTokenPath = "./tokens/.twitchtoken"
|
twitchTokenPath = "./tokens/.twitchtoken"
|
||||||
subdayDataPath = "./backups/subday"
|
subdayDataPath = "./backups/subday"
|
||||||
petDataPath = "./backups/pets"
|
|
||||||
youtubeTokenPath = "./tokens/.youtubetoken"
|
youtubeTokenPath = "./tokens/.youtubetoken"
|
||||||
webLoginsPath = "./tokens/.weblogins"
|
webLoginsPath = "./tokens/.weblogins"
|
||||||
|
|
||||||
|
@ -44,7 +43,6 @@ type (
|
||||||
TwitchToken string
|
TwitchToken string
|
||||||
YoutubeToken string
|
YoutubeToken string
|
||||||
SubdayDataPath string
|
SubdayDataPath string
|
||||||
PetDataPath string
|
|
||||||
PermittedRoles []string
|
PermittedRoles []string
|
||||||
DiscordVoiceChannel string
|
DiscordVoiceChannel string
|
||||||
Songs []SongInfo
|
Songs []SongInfo
|
||||||
|
@ -87,7 +85,6 @@ func New() (*Settings, error) {
|
||||||
TwitchUser: twitchUser,
|
TwitchUser: twitchUser,
|
||||||
TwitchIRCRoom: twitchIRCRoom,
|
TwitchIRCRoom: twitchIRCRoom,
|
||||||
SubdayDataPath: subdayDataPath,
|
SubdayDataPath: subdayDataPath,
|
||||||
PetDataPath: petDataPath,
|
|
||||||
DiscordVoiceChannel: "301793085522706432",
|
DiscordVoiceChannel: "301793085522706432",
|
||||||
PermittedRoles: []string{subRole1, subRole2, galchedRole, smorcRole},
|
PermittedRoles: []string{subRole1, subRole2, galchedRole, smorcRole},
|
||||||
Songs: []SongInfo{
|
Songs: []SongInfo{
|
||||||
|
|
|
@ -1,257 +0,0 @@
|
||||||
package twitchat
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"hash/fnv"
|
|
||||||
"math/rand"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gempir/go-twitch-irc/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
const emoteMsg = "!emote"
|
|
||||||
|
|
||||||
var (
|
|
||||||
emotes = []string{
|
|
||||||
"4Head",
|
|
||||||
"ANELE",
|
|
||||||
"ArgieB8",
|
|
||||||
"ArsonNoSexy",
|
|
||||||
"AsexualPride",
|
|
||||||
"AsianGlow",
|
|
||||||
"BCWarrior",
|
|
||||||
"BOP",
|
|
||||||
"BabyRage",
|
|
||||||
"BatChest",
|
|
||||||
"BegWan",
|
|
||||||
"BibleThump",
|
|
||||||
"BigBrother",
|
|
||||||
"BigPhish",
|
|
||||||
"BisexualPride",
|
|
||||||
"BlargNaut",
|
|
||||||
"BlessRNG",
|
|
||||||
"BloodTrail",
|
|
||||||
"BrainSlug",
|
|
||||||
"BrokeBack",
|
|
||||||
"BuddhaBar",
|
|
||||||
"CarlSmile",
|
|
||||||
"ChefFrank",
|
|
||||||
"CoolCat",
|
|
||||||
"CoolStoryBob",
|
|
||||||
"CorgiDerp",
|
|
||||||
"CrreamAwk",
|
|
||||||
"CurseLit",
|
|
||||||
"DAESuppy",
|
|
||||||
"DBstyle",
|
|
||||||
"DansGame",
|
|
||||||
"DarkMode",
|
|
||||||
"DatSheffy",
|
|
||||||
"DendiFace",
|
|
||||||
"DogFace",
|
|
||||||
"DoritosChip",
|
|
||||||
"DrinkPurple",
|
|
||||||
"DxCat",
|
|
||||||
"EarthDay",
|
|
||||||
"EleGiggle",
|
|
||||||
"EntropyWins",
|
|
||||||
"FBBlock",
|
|
||||||
"FBCatch",
|
|
||||||
"FBChallenge",
|
|
||||||
"FBPass",
|
|
||||||
"FBPenalty",
|
|
||||||
"FBRun",
|
|
||||||
"FBSpiral",
|
|
||||||
"FBtouchdown",
|
|
||||||
"FUNgineer",
|
|
||||||
"FailFish",
|
|
||||||
"FrankerZ",
|
|
||||||
"FreakinStinkin",
|
|
||||||
"FutureMan",
|
|
||||||
"GayPride",
|
|
||||||
"GenderFluidPride",
|
|
||||||
"GingerPower",
|
|
||||||
"GivePLZ",
|
|
||||||
"GrammarKing",
|
|
||||||
"GreenTeam",
|
|
||||||
"GunRun",
|
|
||||||
"HSCheers",
|
|
||||||
"HSWP",
|
|
||||||
"HassaanChop",
|
|
||||||
"HassanChop",
|
|
||||||
"HeyGuys",
|
|
||||||
"HolidayCookie",
|
|
||||||
"HolidayLog",
|
|
||||||
"HolidayOrnament",
|
|
||||||
"HolidayPresent",
|
|
||||||
"HolidaySanta",
|
|
||||||
"HolidayTree",
|
|
||||||
"HotPokket",
|
|
||||||
"HumbleLife",
|
|
||||||
"IntersexPride",
|
|
||||||
"InuyoFace",
|
|
||||||
"ItsBoshyTime",
|
|
||||||
"JKanStyle",
|
|
||||||
"Jebaited",
|
|
||||||
"JonCarnage",
|
|
||||||
"KAPOW",
|
|
||||||
"Kappa",
|
|
||||||
"KappaClaus",
|
|
||||||
"KappaPride",
|
|
||||||
"KappaRoss",
|
|
||||||
"KappaWealth",
|
|
||||||
"Kappu",
|
|
||||||
"Keepo",
|
|
||||||
"KevinTurtle",
|
|
||||||
"Kippa",
|
|
||||||
"KomodoHype",
|
|
||||||
"KonCha",
|
|
||||||
"Kreygasm",
|
|
||||||
"LUL",
|
|
||||||
"LesbianPride",
|
|
||||||
"MVGame",
|
|
||||||
"Mau5",
|
|
||||||
"MaxLOL",
|
|
||||||
"MercyWing1",
|
|
||||||
"MercyWing2",
|
|
||||||
"MikeHogu",
|
|
||||||
"MingLee",
|
|
||||||
"MorphinTime",
|
|
||||||
"MrDestructoid",
|
|
||||||
"NinjaGrumpy",
|
|
||||||
"NomNom",
|
|
||||||
"NonBinaryPride",
|
|
||||||
"NotATK",
|
|
||||||
"NotLikeThis",
|
|
||||||
"OSFrog",
|
|
||||||
"OhMyDog",
|
|
||||||
"OneHand",
|
|
||||||
"OpieOP",
|
|
||||||
"OptimizePrime",
|
|
||||||
"PJSalt",
|
|
||||||
"PJSugar",
|
|
||||||
"PMSTwin",
|
|
||||||
"PRChase",
|
|
||||||
"PanicVis",
|
|
||||||
"PansexualPride",
|
|
||||||
"PartyHat",
|
|
||||||
"PartyTime",
|
|
||||||
"PeoplesChamp",
|
|
||||||
"PermaSmug",
|
|
||||||
"PicoMause",
|
|
||||||
"PinkMercy",
|
|
||||||
"PipeHype",
|
|
||||||
"PixelBob",
|
|
||||||
"PogChamp",
|
|
||||||
"Poooound",
|
|
||||||
"PopCorn",
|
|
||||||
"PorscheWIN",
|
|
||||||
"PowerUpL",
|
|
||||||
"PowerUpR",
|
|
||||||
"PraiseIt",
|
|
||||||
"PrimeMe",
|
|
||||||
"PunOko",
|
|
||||||
"PunchTrees",
|
|
||||||
"PurpleStar",
|
|
||||||
"RaccAttack",
|
|
||||||
"RalpherZ",
|
|
||||||
"RedCoat",
|
|
||||||
"RedTeam",
|
|
||||||
"ResidentSleeper",
|
|
||||||
"RitzMitz",
|
|
||||||
"RlyTho",
|
|
||||||
"RuleFive",
|
|
||||||
"SMOrc",
|
|
||||||
"SSSsss",
|
|
||||||
"SabaPing",
|
|
||||||
"SeemsGood",
|
|
||||||
"SeriousSloth",
|
|
||||||
"ShadyLulu",
|
|
||||||
"ShazBotstix",
|
|
||||||
"SingsMic",
|
|
||||||
"SingsNote",
|
|
||||||
"SmoocherZ",
|
|
||||||
"SoBayed",
|
|
||||||
"SoonerLater",
|
|
||||||
"Squid1",
|
|
||||||
"Squid2",
|
|
||||||
"Squid3",
|
|
||||||
"Squid4",
|
|
||||||
"StinkyCheese",
|
|
||||||
"StoneLightning",
|
|
||||||
"StrawBeary",
|
|
||||||
"SuperVinlin",
|
|
||||||
"SwiftRage",
|
|
||||||
"TBAngel",
|
|
||||||
"TF2John",
|
|
||||||
"TPFufun",
|
|
||||||
"TPcrunchyroll",
|
|
||||||
"TTours",
|
|
||||||
"TakeNRG",
|
|
||||||
"TearGlove",
|
|
||||||
"TehePelo",
|
|
||||||
"ThankEgg",
|
|
||||||
"TheIlluminati",
|
|
||||||
"TheRinger",
|
|
||||||
"TheTarFu",
|
|
||||||
"TheThing",
|
|
||||||
"ThunBeast",
|
|
||||||
"TinyFace",
|
|
||||||
"TombRaid",
|
|
||||||
"TooSpicy",
|
|
||||||
"TransgenderPride",
|
|
||||||
"TriHard",
|
|
||||||
"TwitchLit",
|
|
||||||
"TwitchRPG",
|
|
||||||
"TwitchSings",
|
|
||||||
"TwitchUnity",
|
|
||||||
"TwitchVotes",
|
|
||||||
"UWot",
|
|
||||||
"UnSane",
|
|
||||||
"UncleNox",
|
|
||||||
"VoHiYo",
|
|
||||||
"VoteNay",
|
|
||||||
"VoteYea",
|
|
||||||
"WTRuck",
|
|
||||||
"WholeWheat",
|
|
||||||
"WutFace",
|
|
||||||
"YouDontSay",
|
|
||||||
"YouWHY",
|
|
||||||
"bleedPurple",
|
|
||||||
"cmonBruh",
|
|
||||||
"copyThis",
|
|
||||||
"duDudu",
|
|
||||||
"imGlitch",
|
|
||||||
"mcaT",
|
|
||||||
"panicBasket",
|
|
||||||
"pastaThat",
|
|
||||||
"riPepperonis",
|
|
||||||
"twitchRaid",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
dailyEmote struct{}
|
|
||||||
)
|
|
||||||
|
|
||||||
func DailyEmote() *dailyEmote {
|
|
||||||
return new(dailyEmote)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *dailyEmote) IsValid(m *twitch.PrivateMessage) bool {
|
|
||||||
return (m.Tags["msg-id"] == "highlighted-message") && m.Message == emoteMsg
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *dailyEmote) Handle(m *twitch.PrivateMessage, r Responser) {
|
|
||||||
data := time.Now().Format("2006-01-02") + m.User.DisplayName
|
|
||||||
rng := rand.New(rand.NewSource(hashSeed(data)))
|
|
||||||
emote := emotes[rng.Intn(len(emotes))]
|
|
||||||
|
|
||||||
msg := fmt.Sprintf("@%s твой эмоут дня: %s", m.User.DisplayName, emote)
|
|
||||||
r.Say(m.Channel, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func hashSeed(s string) int64 {
|
|
||||||
h := fnv.New64()
|
|
||||||
h.Write([]byte(s))
|
|
||||||
return int64(h.Sum64())
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package twitchat
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"galched-bot/modules/patpet"
|
|
||||||
"github.com/gempir/go-twitch-irc/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
petMsg1 = "!погладь"
|
|
||||||
petMsg2 = "!гладь"
|
|
||||||
petMsg3 = "!погладить"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
petCat struct {
|
|
||||||
cat *patpet.Pet
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func PetCat(pet *patpet.Pet) *petCat {
|
|
||||||
return &petCat{
|
|
||||||
cat: pet,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *petCat) IsValid(m *twitch.PrivateMessage) bool {
|
|
||||||
return (m.Tags["msg-id"] == "highlighted-message") && (strings.HasPrefix(m.Message, petMsg1) ||
|
|
||||||
strings.HasPrefix(m.Message, petMsg2) ||
|
|
||||||
strings.HasPrefix(m.Message, petMsg3))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *petCat) Handle(m *twitch.PrivateMessage, r Responser) {
|
|
||||||
msg := fmt.Sprintf("Котэ поглажен уже %d раз(а) InuyoFace", h.cat.Pet())
|
|
||||||
r.Say(m.Channel, msg)
|
|
||||||
h.cat.Dump()
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
package twitchat
|
package twitchat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"galched-bot/modules/patpet"
|
|
||||||
"galched-bot/modules/settings"
|
"galched-bot/modules/settings"
|
||||||
"galched-bot/modules/youtube"
|
"galched-bot/modules/youtube"
|
||||||
|
|
||||||
|
@ -16,15 +15,13 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(s *settings.Settings, r *youtube.Requester, pet *patpet.Pet) (*TwitchIRC, error) {
|
func New(s *settings.Settings, r *youtube.Requester) (*TwitchIRC, error) {
|
||||||
var irc = new(TwitchIRC)
|
var irc = new(TwitchIRC)
|
||||||
|
|
||||||
irc.username = s.TwitchUser
|
irc.username = s.TwitchUser
|
||||||
|
|
||||||
irc.handlers = append(irc.handlers, DupHandler())
|
irc.handlers = append(irc.handlers, DupHandler())
|
||||||
irc.handlers = append(irc.handlers, DailyEmote())
|
|
||||||
irc.handlers = append(irc.handlers, SongRequest(r))
|
irc.handlers = append(irc.handlers, SongRequest(r))
|
||||||
irc.handlers = append(irc.handlers, PetCat(pet))
|
|
||||||
// irc.handlers = append(irc.handlers, LogCheck())
|
// irc.handlers = append(irc.handlers, LogCheck())
|
||||||
|
|
||||||
irc.chat = twitch.NewClient(s.TwitchUser, s.TwitchToken)
|
irc.chat = twitch.NewClient(s.TwitchUser, s.TwitchToken)
|
||||||
|
|
Loading…
Add table
Reference in a new issue