mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
styling and cleanup
This commit is contained in:
parent
4bfc29c1b6
commit
6911603401
|
@ -49,11 +49,13 @@ func (app *application) AddCommand(name string, message twitch.PrivateMessage) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetCommand queries the database for a command with the provided name. If an entry exists
|
||||
// it checks if the Command.Level is 0, if it is the command.Text value is returned.
|
||||
// GetCommand queries the database for a command with the provided name.
|
||||
// If an entry exists it checks if the Command.Level is 0, if it is
|
||||
// the command.Text value is returned.
|
||||
//
|
||||
// If the Command.Level is not 0 it queries the database for the level of the user who sent
|
||||
// the message. If the users level is equal or higher the command.Text field is returned.
|
||||
// If the Command.Level is not 0 it queries the database for the level of the
|
||||
// user who sent the message. If the users level is equal or higher
|
||||
// the command.Text field is returned.
|
||||
func (app *application) GetCommand(target, commandName string, userLevel int) (string, error) {
|
||||
app.Log.Infow("command",
|
||||
"target", target,
|
||||
|
@ -78,11 +80,14 @@ func (app *application) GetCommand(target, commandName string, userLevel int) (s
|
|||
return "", ErrUserInsufficientLevel
|
||||
}
|
||||
|
||||
// GetCommandDescription queries the database for a command with the provided name in the channel.
|
||||
// If a command exist it then checks if the Command.Level is 0, if it is the command.Text value is returned.
|
||||
// GetCommandDescription queries the database for a command with the provided
|
||||
// name in the channel.
|
||||
// If a command exist it then checks if the Command.Level is 0, if it is
|
||||
// the command.Text value is returned.
|
||||
//
|
||||
// If the Command.Level is not 0 it queries the database for the level of the user who sent
|
||||
// the message. If the users level is equal or higher the command.Text field is returned.
|
||||
// If the Command.Level is not 0 it queries the database for the level of
|
||||
// the user that sent the message. If the users level is equal or higher
|
||||
// the command.Text field is returned.
|
||||
func (app *application) GetCommandDescription(name, channel, username string) (string, error) {
|
||||
command, err := app.Models.Commands.Get(name, channel)
|
||||
if err != nil {
|
||||
|
@ -110,25 +115,31 @@ func (app *application) GetCommandDescription(name, channel, username string) (s
|
|||
return "", ErrUserInsufficientLevel
|
||||
}
|
||||
|
||||
// EditCommandLevel checks if a command with the provided name exists in the database. If it does it
|
||||
// changes the level of the command with the supplied value.
|
||||
// EditCommandLevel checks if a command with the provided name exists in
|
||||
// the database. If it exists it changes the level of the command in
|
||||
// the database with the newly supplied level value.
|
||||
func (app *application) EditCommandLevel(name, lvl string, message twitch.PrivateMessage) {
|
||||
level, err := strconv.Atoi(lvl)
|
||||
|
||||
if err != nil {
|
||||
app.Log.Error(err)
|
||||
app.Send(message.Channel, fmt.Sprintf("Something went wrong FeelsBadMan %s", ErrCommandLevelNotInteger), message)
|
||||
app.Send(message.Channel,
|
||||
fmt.Sprintf("Something went wrong FeelsBadMan %s", ErrCommandLevelNotInteger), message)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
err = app.Models.Commands.SetLevel(name, message.Channel, level)
|
||||
|
||||
if err != nil {
|
||||
app.Send(message.Channel, fmt.Sprintf("Something went wrong FeelsBadMan %s", ErrRecordNotFound), message)
|
||||
app.Send(message.Channel,
|
||||
fmt.Sprintf("Something went wrong FeelsBadMan %s", ErrRecordNotFound), message)
|
||||
app.Log.Error(err)
|
||||
|
||||
return
|
||||
} else {
|
||||
reply := fmt.Sprintf("Updated command %s to level %v", name, level)
|
||||
app.Send(message.Channel, reply, message)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -279,11 +290,10 @@ func (app *application) ListChannelCommands(channel string) string {
|
|||
|
||||
// The slice of timers is only used to log them at
|
||||
// the start so it looks a bit nicer.
|
||||
var cs []string
|
||||
|
||||
allHelpText := app.GetAllHelpText()
|
||||
var cs = []string{fmt.Sprintf("General commands: \n\n%s\nChannel commands:\n\n", allHelpText)}
|
||||
app.Log.Info(allHelpText)
|
||||
cs = append(cs, fmt.Sprintf("General commands: \n\n%s\nChannel commands:\n\n", allHelpText))
|
||||
|
||||
// Iterate over all timers and then add them onto the scheduler.
|
||||
for i, v := range command {
|
||||
|
@ -291,9 +301,8 @@ func (app *application) ListChannelCommands(channel string) string {
|
|||
// https://github.com/robfig/cron/issues/420#issuecomment-940949195
|
||||
i, v := i, v
|
||||
_ = i
|
||||
var c string
|
||||
|
||||
c = fmt.Sprintf(
|
||||
c := fmt.Sprintf(
|
||||
"Name: \t%v\n"+
|
||||
"Description: %v\n"+
|
||||
"Level: \t%v\n"+
|
||||
|
|
|
@ -12,8 +12,9 @@ import (
|
|||
"github.com/lyx0/nourybot/pkg/owm"
|
||||
)
|
||||
|
||||
// handleCommand takes in a twitch.PrivateMessage and then routes the message to
|
||||
// the function that is responsible for each command and knows how to deal with it accordingly.
|
||||
// handleCommand takes in a twitch.PrivateMessage and then routes the message
|
||||
// to the function that is responsible for each command and knows how to deal
|
||||
// with it accordingly.
|
||||
func (app *application) handleCommand(message twitch.PrivateMessage) {
|
||||
var reply string
|
||||
|
||||
|
@ -21,7 +22,8 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
|||
return
|
||||
}
|
||||
|
||||
// Increments the counter how many commands have been used, called in the ping command.
|
||||
// Increments the counter how many commands have been used,
|
||||
// called in the ping command.
|
||||
go common.CommandUsed()
|
||||
|
||||
go app.InitUser(message.User.Name, message.User.ID)
|
||||
|
@ -134,6 +136,9 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
|||
case "youtube":
|
||||
reply = commands.Youtube(message.Message[10:len(message.Message)])
|
||||
|
||||
case "godoc":
|
||||
reply = commands.Godocs(message.Message[8:len(message.Message)])
|
||||
|
||||
case "godocs":
|
||||
reply = commands.Godocs(message.Message[9:len(message.Message)])
|
||||
|
||||
|
@ -202,10 +207,10 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
|||
reply, _ = app.getUserID(cmdParams[1])
|
||||
|
||||
case "uname":
|
||||
reply, _ = app.getChannelUsername(cmdParams[1])
|
||||
reply, _ = app.userIDtoUsername(cmdParams[1])
|
||||
|
||||
case "username":
|
||||
reply, _ = app.getChannelUsername(cmdParams[1])
|
||||
reply, _ = app.userIDtoUsername(cmdParams[1])
|
||||
|
||||
case "commands":
|
||||
reply = app.ListChannelCommands(message.Channel)
|
||||
|
@ -549,10 +554,10 @@ var helpText = map[string]command{
|
|||
},
|
||||
"godocs": {
|
||||
Name: "godocs",
|
||||
Alias: nil,
|
||||
Alias: []string{"godocs", "godoc"},
|
||||
Description: "Returns the godocs.io search URL for a given query.",
|
||||
Level: "0",
|
||||
Usage: "()godoc <query>",
|
||||
Usage: "()godocs <query>",
|
||||
},
|
||||
"gofile": {
|
||||
Name: "gofile",
|
||||
|
@ -753,7 +758,7 @@ var helpText = map[string]command{
|
|||
"weather": {
|
||||
Name: "weather",
|
||||
Alias: nil,
|
||||
Description: `Returns the weather for a given location. If you "$set location" your location, the command will use that location if no other location is specified.`,
|
||||
Description: `Returns the weather for a given location. If you "()set location" your location, the command will use that location if no other location is specified.`,
|
||||
Level: "0",
|
||||
Usage: "()weather [location]",
|
||||
},
|
||||
|
@ -810,9 +815,19 @@ func (app *application) GetAllHelpText() string {
|
|||
var c string
|
||||
|
||||
if v.Alias == nil {
|
||||
c = fmt.Sprintf("Name: %s\nDescription: %s\nLevel: %s\nUsage: %s\n\n", i, v.Description, v.Level, v.Usage)
|
||||
c = fmt.Sprintf("Name: %s\nDescription: %s\nLevel: %s\nUsage: %s\n\n",
|
||||
i,
|
||||
v.Description,
|
||||
v.Level,
|
||||
v.Usage,
|
||||
)
|
||||
} else {
|
||||
c = fmt.Sprintf("Name: %s\nAliases: %s\nDescription: %s\nLevel: %s\nUsage: %s\n\n", i, v.Alias, v.Description, v.Level, v.Usage)
|
||||
c = fmt.Sprintf("Name: %s\nAliases: %s\nDescription: %s\nLevel: %s\nUsage: %s\n\n",
|
||||
i, v.Alias,
|
||||
v.Description,
|
||||
v.Level,
|
||||
v.Usage,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ func (app *application) ConvertAndSave(fName, link string, msg twitch.PrivateMes
|
|||
fn, err := os.Create(out)
|
||||
if err != nil {
|
||||
app.Log.Errorln(err)
|
||||
app.Send(msg.Channel, fmt.Sprintf("Something went wrong FeelsBadMan: %q", err), msg)
|
||||
app.Send(msg.Channel, fmt.Sprint(ErrGenericErrorMessage), msg)
|
||||
return
|
||||
}
|
||||
defer fn.Close()
|
||||
|
@ -95,6 +95,11 @@ func (app *application) ConvertAndSave(fName, link string, msg twitch.PrivateMes
|
|||
err = ffmpeg.Input(fileName).
|
||||
Output(out).
|
||||
OverWriteOutput().ErrorToStdOut().Run()
|
||||
if err != nil {
|
||||
app.Log.Errorln(err)
|
||||
app.Send(msg.Channel, fmt.Sprint(ErrGenericErrorMessage), msg)
|
||||
return
|
||||
}
|
||||
|
||||
defer os.Remove(fileName)
|
||||
app.Send(msg.Channel, fmt.Sprintf("https://bot.noury.li/uploads/%s.mp4", fName), msg)
|
||||
|
@ -160,6 +165,11 @@ func (app *application) ConvertToMP4(link string, msg twitch.PrivateMessage) {
|
|||
err = ffmpeg.Input(fileName).
|
||||
Output(out).
|
||||
OverWriteOutput().ErrorToStdOut().Run()
|
||||
if err != nil {
|
||||
app.Log.Errorln(err)
|
||||
app.Send(msg.Channel, fmt.Sprint(ErrGenericErrorMessage), msg)
|
||||
return
|
||||
}
|
||||
|
||||
defer os.Remove(fileName)
|
||||
go app.NewUpload("yaf", out, msg.Channel, uuid_new, msg)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
ErrGenericErrorMessage = errors.New("something went wrong FeelsBadMan")
|
||||
ErrUserLevelNotInteger = errors.New("user level must be a number")
|
||||
ErrCommandLevelNotInteger = errors.New("command level must be a number")
|
||||
ErrRecordNotFound = errors.New("user not found in the database")
|
||||
|
|
|
@ -103,7 +103,8 @@ func (app *application) deleteLiveSubscription(target, channel string) string {
|
|||
return fmt.Sprintf("Successfully deleted live notification for channel %s; id=%v", channel, uid)
|
||||
}
|
||||
|
||||
// createOfflineSubscription creates a stream.offline twitch eventsub subscription for the specified channel
|
||||
// createOfflineSubscription creates a stream.offline twitch eventsub
|
||||
// subscription for the specified channel.
|
||||
func (app *application) createOfflineSubscription(target, channel string) string {
|
||||
uid := ivr.IDByUsername(channel)
|
||||
if uid == "xd" {
|
||||
|
@ -133,7 +134,8 @@ func (app *application) createOfflineSubscription(target, channel string) string
|
|||
return fmt.Sprintf("Created offline subscription for channel %v; uid=%v", channel, uid)
|
||||
}
|
||||
|
||||
// deleteOfflineSubscription deletes a stream.offline twitch eventsub subscription for the specified channel
|
||||
// deleteOfflineSubscription deletes a stream.offline twitch eventsub
|
||||
// subscription for the specified channel
|
||||
func (app *application) deleteOfflineSubscription(target, channel string) string {
|
||||
uid := ivr.IDByUsername(channel)
|
||||
if uid == "xd" {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/nicklaw5/helix/v2"
|
||||
)
|
||||
|
||||
// getUserID returns the Twitch userID for given twitch username.
|
||||
func (app *application) getUserID(username string) (string, error) {
|
||||
resp, err := app.HelixClient.GetUsers(&helix.UsersParams{
|
||||
Logins: []string{username},
|
||||
|
@ -16,7 +17,8 @@ func (app *application) getUserID(username string) (string, error) {
|
|||
return resp.Data.Users[0].ID, nil
|
||||
}
|
||||
|
||||
func (app *application) getChannelUsername(channelID string) (string, error) {
|
||||
// userIDtoUsername returns the Twitch username for a given twitch user ID.
|
||||
func (app *application) userIDtoUsername(channelID string) (string, error) {
|
||||
resp, err := app.HelixClient.GetUsers(&helix.UsersParams{
|
||||
IDs: []string{channelID},
|
||||
})
|
||||
|
@ -28,6 +30,8 @@ func (app *application) getChannelUsername(channelID string) (string, error) {
|
|||
return resp.Data.Users[0].Login, nil
|
||||
}
|
||||
|
||||
// getChannelTitle queries the Twitch API for the current Title for
|
||||
// the provided Twitch channel username.
|
||||
func (app *application) getChannelTitle(channelID string) string {
|
||||
resp, err := app.HelixClient.GetChannelInformation(&helix.GetChannelInformationParams{
|
||||
BroadcasterID: channelID,
|
||||
|
@ -40,6 +44,8 @@ func (app *application) getChannelTitle(channelID string) string {
|
|||
return resp.Data.Channels[0].Title
|
||||
}
|
||||
|
||||
// getChannelTitleByUsername returns the current title of the provided
|
||||
// Twitch channel username.
|
||||
func (app *application) getChannelTitleByUsername(username string) string {
|
||||
channelID, err := app.getUserID(username)
|
||||
if err != nil {
|
||||
|
|
|
@ -178,11 +178,15 @@ func run(ctx context.Context, w io.Writer, args []string) error {
|
|||
|
||||
app.TwitchClient.OnClearChatMessage(func(message twitch.ClearChatMessage) {
|
||||
if message.BanDuration == 0 && message.Channel == "forsen" {
|
||||
app.TwitchClient.Say("nouryxd", fmt.Sprintf("MODS https://logs.ivr.fi/?channel=forsen&username=%v", message.TargetUsername))
|
||||
app.TwitchClient.Say("nouryxd",
|
||||
fmt.Sprintf("MODS https://logs.ivr.fi/?channel=forsen&username=%v",
|
||||
message.TargetUsername))
|
||||
}
|
||||
|
||||
if message.BanDuration >= 28700 && message.Channel == "forsen" {
|
||||
app.TwitchClient.Say("nouryxd", fmt.Sprintf("monkaS -%v https://logs.ivr.fi/?channel=forsen&username=%v", message.BanDuration, message.TargetUsername))
|
||||
app.TwitchClient.Say("nouryxd",
|
||||
fmt.Sprintf("monkaS -%v https://logs.ivr.fi/?channel=forsen&username=%v",
|
||||
message.BanDuration, message.TargetUsername))
|
||||
}
|
||||
|
||||
})
|
||||
|
|
|
@ -27,7 +27,7 @@ func (app *application) startRouter() {
|
|||
router.GET("/timer", app.timersRoute)
|
||||
router.GET("/timer/:channel", app.channelTimersRoute)
|
||||
|
||||
// Serve files uploaded by the meme command, but don't list the directory contents.
|
||||
// Serve files uploaded by the meme command, but don't list directory contents.
|
||||
fs := justFilesFilesystem{http.Dir("/public/uploads/")}
|
||||
router.Handler("GET", "/uploads/*filepath", http.StripPrefix("/uploads", http.FileServer(fs)))
|
||||
|
||||
|
@ -41,10 +41,11 @@ type eventSubNotification struct {
|
|||
Event json.RawMessage `json:"event"`
|
||||
}
|
||||
|
||||
// eventsubMessageId stores the last message id of an event sub. Twitch resends events
|
||||
// if it is unsure that you have gotten them so we check if the last event has the same
|
||||
// message id and if it does discard the event.
|
||||
var lastEventSubSubscriptionId = []string{"xd"}
|
||||
// eventsubSubscriptionID stores the received eventsub subscription ids since
|
||||
// last restart. Twitch resends events if it is unsure that we have gotten them
|
||||
// so we check if the received eventsub subscription id has already
|
||||
// been recorded and discard them if so.
|
||||
var lastEventSubSubscriptionID = []string{"xd"}
|
||||
|
||||
func (app *application) eventsubFollow(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
channel := ps.ByName("channel")
|
||||
|
@ -68,7 +69,8 @@ func (app *application) eventsubFollow(w http.ResponseWriter, r *http.Request, p
|
|||
log.Println(err)
|
||||
return
|
||||
}
|
||||
// if there's a challenge in the request, respond with only the challenge to verify your eventsub.
|
||||
// if there's a challenge in the request, respond
|
||||
// with only the challenge to verify the request is genuine.
|
||||
if vals.Challenge != "" {
|
||||
w.Write([]byte(vals.Challenge))
|
||||
return
|
||||
|
@ -77,11 +79,11 @@ func (app *application) eventsubFollow(w http.ResponseWriter, r *http.Request, p
|
|||
|
||||
// Check if the current events subscription id equals the last events.
|
||||
// If it does ignore the event since it's a repeated event.
|
||||
for i := 0; i < len(lastEventSubSubscriptionId); i++ {
|
||||
if vals.Subscription.ID == lastEventSubSubscriptionId[i] {
|
||||
for i := 0; i < len(lastEventSubSubscriptionID); i++ {
|
||||
if vals.Subscription.ID == lastEventSubSubscriptionID[i] {
|
||||
return
|
||||
} else {
|
||||
lastEventSubSubscriptionId[i] = vals.Subscription.ID
|
||||
lastEventSubSubscriptionID[i] = vals.Subscription.ID
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,22 +92,39 @@ func (app *application) eventsubFollow(w http.ResponseWriter, r *http.Request, p
|
|||
var liveEvent helix.EventSubStreamOnlineEvent
|
||||
|
||||
err = json.NewDecoder(bytes.NewReader(vals.Event)).Decode(&liveEvent)
|
||||
log.Printf("got stream online event webhook: [%s]: %s is live\n", channel, liveEvent.BroadcasterUserName)
|
||||
if err != nil {
|
||||
app.Log.Errorln(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("got stream online event webhook: [%s]: %s is live\n",
|
||||
channel, liveEvent.BroadcasterUserName)
|
||||
w.WriteHeader(200)
|
||||
w.Write([]byte("ok"))
|
||||
|
||||
game := app.getChannelGame(liveEvent.BroadcasterUserID)
|
||||
title := app.getChannelTitle(liveEvent.BroadcasterUserID)
|
||||
|
||||
app.SendNoBanphrase(channel, fmt.Sprintf("%s went live FeelsGoodMan Game: %s; Title: %s; https://twitch.tv/%s", liveEvent.BroadcasterUserName, game, title, liveEvent.BroadcasterUserLogin))
|
||||
go app.SendNoBanphrase(channel,
|
||||
fmt.Sprintf("@%s went live FeelsGoodMan Game: %s; Title: %s; https://twitch.tv/%s",
|
||||
liveEvent.BroadcasterUserName, game, title, liveEvent.BroadcasterUserLogin))
|
||||
|
||||
case helix.EventSubTypeStreamOffline:
|
||||
var offlineEvent helix.EventSubStreamOfflineEvent
|
||||
|
||||
err = json.NewDecoder(bytes.NewReader(vals.Event)).Decode(&offlineEvent)
|
||||
log.Printf("got stream online event webhook: [%s]: %s is live\n", channel, offlineEvent.BroadcasterUserName)
|
||||
if err != nil {
|
||||
app.Log.Errorln(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("got stream offline event webhook: [%s]: %s is offline\n",
|
||||
channel, offlineEvent.BroadcasterUserName)
|
||||
w.WriteHeader(200)
|
||||
w.Write([]byte("ok"))
|
||||
app.SendNoBanphrase(channel, fmt.Sprintf("%s went offline FeelsBadMan", offlineEvent.BroadcasterUserName))
|
||||
|
||||
go app.SendNoBanphrase(channel,
|
||||
fmt.Sprintf("%s went offline FeelsBadMan", offlineEvent.BroadcasterUserName))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,9 +248,13 @@ func (app *application) commandsRoute(w http.ResponseWriter, r *http.Request, _
|
|||
var c string
|
||||
|
||||
if v.Alias == nil {
|
||||
c = fmt.Sprintf("Name: %s\nDescription: %s\nLevel: %s\nUsage: %s\n\n", i, v.Description, v.Level, v.Usage)
|
||||
c = fmt.Sprintf(
|
||||
"Name: %s\nDescription: %s\nLevel: %s\nUsage: %s\n\n",
|
||||
i, v.Description, v.Level, v.Usage)
|
||||
} else {
|
||||
c = fmt.Sprintf("Name: %s\nAliases: %s\nDescription: %s\nLevel: %s\nUsage: %s\n\n", i, v.Alias, v.Description, v.Level, v.Usage)
|
||||
c = fmt.Sprintf(
|
||||
"Name: %s\nAliases: %s\nDescription: %s\nLevel: %s\nUsage: %s\n\n",
|
||||
i, v.Alias, v.Description, v.Level, v.Usage)
|
||||
|
||||
}
|
||||
|
||||
|
@ -336,12 +359,17 @@ func (app *application) statusPageRoute(w http.ResponseWriter, r *http.Request,
|
|||
started := common.GetUptime().Format("2006-1-2 15:4:5")
|
||||
commitLink := fmt.Sprintf("https://github.com/lyx0/nourybot/commit/%v", common.GetVersionPure())
|
||||
|
||||
fmt.Fprintf(w, fmt.Sprintf("started: \t%v\nenvironment: \t%v\ncommit: \t%v\ngithub: \t%v", started, app.Environment, commit, commitLink))
|
||||
fmt.Print(w, fmt.Sprint(
|
||||
"started: \t"+started+"\n"+
|
||||
"environment: \t"+app.Environment+"\n"+
|
||||
"commit: \t"+commit+"\n"+
|
||||
"github: \t"+commitLink,
|
||||
))
|
||||
}
|
||||
|
||||
// Since I want to serve the files that I uploaded with the meme command to the /public/uploads
|
||||
// folder, but not list the directory on the `/uploads/` route I found this issue that solves
|
||||
// that problem with the httprouter.
|
||||
// Since I want to serve the files that I upload with the meme command to
|
||||
// the /public/uploads folder but not list the directory contents of
|
||||
// the `/uploads/` route I found this issue that solves this.
|
||||
//
|
||||
// https://github.com/julienschmidt/httprouter/issues/25#issuecomment-74977940
|
||||
type justFilesFilesystem struct {
|
||||
|
|
|
@ -93,7 +93,8 @@ func (app *application) SendNoContext(target, message string) {
|
|||
}
|
||||
|
||||
identifier := uuid.NewString()
|
||||
go app.Models.SentMessagesLogs.Insert(target, message, "unavailable", "unavailable", "unavailable", "unavailable", identifier, "unavailable")
|
||||
go app.Models.SentMessagesLogs.Insert(
|
||||
target, message, "unavailable", "unavailable", "unavailable", "unavailable", identifier, "unavailable")
|
||||
|
||||
// Since messages starting with `.` or `/` are used for special actions
|
||||
// (ban, whisper, timeout) and so on, we place an emote infront of it so
|
||||
|
@ -152,7 +153,8 @@ func (app *application) Send(target, message string, msgContext twitch.PrivateMe
|
|||
|
||||
commandName := strings.ToLower(strings.SplitN(msgContext.Message, " ", 3)[0][2:])
|
||||
identifier := uuid.NewString()
|
||||
go app.Models.SentMessagesLogs.Insert(target, message, commandName, msgContext.User.Name, msgContext.User.ID, msgContext.Message, identifier, msgContext.Raw)
|
||||
go app.Models.SentMessagesLogs.Insert(
|
||||
target, message, commandName, msgContext.User.Name, msgContext.User.ID, msgContext.Message, identifier, msgContext.Raw)
|
||||
|
||||
// Since messages starting with `.` or `/` are used for special actions
|
||||
// (ban, whisper, timeout) and so on, we place an emote infront of it so
|
||||
|
@ -209,7 +211,8 @@ func (app *application) SendNoBanphrase(target, message string) {
|
|||
}
|
||||
|
||||
identifier := uuid.NewString()
|
||||
go app.Models.SentMessagesLogs.Insert(target, message, "unavailable", "unavailable", "unavailable", "unavailable", identifier, "unavailable")
|
||||
go app.Models.SentMessagesLogs.Insert(
|
||||
target, message, "unavailable", "unavailable", "unavailable", "unavailable", identifier, "unavailable")
|
||||
|
||||
// Since messages starting with `.` or `/` are used for special actions
|
||||
// (ban, whisper, timeout) and so on, we place an emote infront of it so
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
// new data.Timer struct so that the timer can be inserted into the database.
|
||||
func (app *application) AddTimer(name, repeat string, message twitch.PrivateMessage) {
|
||||
cmdParams := strings.SplitN(message.Message, " ", 500)
|
||||
// prefixLength is the length of `()add timer` plus +2 (for the space and zero based)
|
||||
prefix := "()add timer"
|
||||
prefixLength := len("()add timer")
|
||||
nameLength := len(name)
|
||||
|
@ -319,7 +318,8 @@ func (app *application) DeleteTimer(name string, message twitch.PrivateMessage)
|
|||
app.Send(message.Channel, reply, message)
|
||||
}
|
||||
|
||||
// DebugChannelTimers queries the database for all timers in channel and uploads the contents as a paste.
|
||||
// DebugChannelTimers queries the database for all timers in channel
|
||||
// and uploads the contents as a paste.
|
||||
func (app *application) DebugChannelTimers(channel string) string {
|
||||
timer, err := app.Models.Timers.GetChannelTimer(channel)
|
||||
if err != nil {
|
||||
|
@ -337,9 +337,8 @@ func (app *application) DebugChannelTimers(channel string) string {
|
|||
// https://github.com/robfig/cron/issues/420#issuecomment-940949195
|
||||
i, v := i, v
|
||||
_ = i
|
||||
var t string
|
||||
|
||||
t = fmt.Sprintf(
|
||||
t := fmt.Sprintf(
|
||||
"Name: \t%v\n"+
|
||||
"ID: \t%v\n"+
|
||||
"Identifier: \t%v\n"+
|
||||
|
@ -363,7 +362,8 @@ func (app *application) DebugChannelTimers(channel string) string {
|
|||
return reply
|
||||
}
|
||||
|
||||
// ListchannelTimer queries the database for all timers in channel and uploads the contents as a paste.
|
||||
// ListchannelTimer queries the database for all timers in channel and
|
||||
// uploads the contents as a paste.
|
||||
func (app *application) ListChannelTimer(channel string) string {
|
||||
timer, err := app.Models.Timers.GetChannelTimer(channel)
|
||||
if err != nil {
|
||||
|
@ -379,9 +379,8 @@ func (app *application) ListChannelTimer(channel string) string {
|
|||
// https://github.com/robfig/cron/issues/420#issuecomment-940949195
|
||||
i, v := i, v
|
||||
_ = i
|
||||
var t string
|
||||
|
||||
t = fmt.Sprintf(
|
||||
t := fmt.Sprintf(
|
||||
"Name: %v\n"+
|
||||
"Text: %v\n"+
|
||||
"Repeat: %v\n"+
|
||||
|
|
|
@ -392,7 +392,6 @@ func (app *application) YafUpload(target, path, identifier string, msg twitch.Pr
|
|||
var reply = string(body[:])
|
||||
|
||||
go app.Models.Uploads.UpdateUploadURL(identifier, reply)
|
||||
//app.Send(target, fmt.Sprintf("Removing file: %s", path), msg)
|
||||
app.Send(target, reply, msg)
|
||||
}
|
||||
|
||||
|
@ -488,6 +487,5 @@ func (app *application) YafUploadString(text string) string {
|
|||
|
||||
var reply = string(body[:])
|
||||
|
||||
//app.Send(target, fmt.Sprintf("Removing file: %s", path), msg)
|
||||
return reply
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ func (app *application) DebugUser(login string, message twitch.PrivateMessage) {
|
|||
resp, err := app.uploadPaste(body)
|
||||
if err != nil {
|
||||
app.Log.Errorln("Could not upload paste:", err)
|
||||
app.Send(message.Channel, fmt.Sprintf("Something went wrong FeelsBadMan %v", ErrDuringPasteUpload), message)
|
||||
app.Send(message.Channel,
|
||||
fmt.Sprintf("Something went wrong FeelsBadMan %v", ErrDuringPasteUpload), message)
|
||||
return
|
||||
}
|
||||
app.Send(message.Channel, resp, message)
|
||||
|
@ -72,13 +73,15 @@ func (app *application) EditUserLevel(login, lvl string, message twitch.PrivateM
|
|||
level, err := strconv.Atoi(lvl)
|
||||
if err != nil {
|
||||
app.Log.Error(err)
|
||||
app.Send(message.Channel, fmt.Sprintf("Something went wrong FeelsBadMan %s", ErrUserLevelNotInteger), message)
|
||||
app.Send(message.Channel,
|
||||
fmt.Sprintf("Something went wrong FeelsBadMan %s", ErrUserLevelNotInteger), message)
|
||||
return
|
||||
}
|
||||
|
||||
err = app.Models.Users.SetLevel(login, level)
|
||||
if err != nil {
|
||||
app.Send(message.Channel, fmt.Sprintf("Something went wrong FeelsBadMan %s", ErrRecordNotFound), message)
|
||||
app.Send(message.Channel,
|
||||
fmt.Sprintf("Something went wrong FeelsBadMan %s", ErrRecordNotFound), message)
|
||||
app.Log.Error(err)
|
||||
return
|
||||
} else {
|
||||
|
@ -101,7 +104,9 @@ func (app *application) SetUserLocation(message twitch.PrivateMessage) {
|
|||
|
||||
err := app.Models.Users.SetLocation(twitchId, location)
|
||||
if err != nil {
|
||||
app.Send(message.Channel, fmt.Sprintf("Something went wrong FeelsBadMan %s", ErrRecordNotFound), message)
|
||||
app.Send(message.Channel,
|
||||
fmt.Sprintf("Something went wrong FeelsBadMan %s", ErrRecordNotFound), message)
|
||||
|
||||
app.Log.Error(err)
|
||||
return
|
||||
} else {
|
||||
|
@ -158,7 +163,8 @@ func (app *application) GetUserLevel(msg twitch.PrivateMessage) int {
|
|||
// UserCheckWeather checks if a user is in the database and if he has a location
|
||||
// provided. If both is true it calls owm.Weather with the location and replies
|
||||
// with the result.
|
||||
// If no location was provided the response will instruct the user how to set a location.
|
||||
// If no location was provided the response will instruct the user
|
||||
// how to set a location.
|
||||
func (app *application) UserCheckWeather(message twitch.PrivateMessage) {
|
||||
target := message.Channel
|
||||
twitchLogin := message.User.Name
|
||||
|
@ -182,7 +188,8 @@ func (app *application) UserCheckWeather(message twitch.PrivateMessage) {
|
|||
// UserCheckWeather checks if a user is in the database and if he has a lastfm
|
||||
// username provided. If both is true it calls lastfm.LastFmUserRecent with the username
|
||||
// and replies with the result.
|
||||
// If no lastfm username was provided the response will instruct the user how to set a lastfm username.
|
||||
// If no lastfm username was provided the response will instruct the user
|
||||
// how to set a lastfm username.
|
||||
func (app *application) UserCheckLastFM(message twitch.PrivateMessage) string {
|
||||
twitchLogin := message.User.Name
|
||||
target := message.Channel
|
||||
|
|
1
go.mod
1
go.mod
|
@ -22,6 +22,7 @@ require (
|
|||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
honnef.co/go/tools v0.4.7 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
2
go.sum
2
go.sum
|
@ -101,4 +101,6 @@ gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
|
||||
honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// StrGenerateRandomNumber generates a random number from
|
||||
|
@ -19,7 +18,6 @@ func StrGenerateRandomNumber(max string) int {
|
|||
fmt.Printf("Supplied value %v is not a number", num)
|
||||
return 0
|
||||
} else {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
return rand.Intn(num)
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +25,6 @@ func StrGenerateRandomNumber(max string) int {
|
|||
// GenerateRandomNumber returns a random number from
|
||||
// a given max value as a int
|
||||
func GenerateRandomNumber(max int) int {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
return rand.Intn(max)
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ func GetVersionPure() string {
|
|||
}
|
||||
|
||||
if modified {
|
||||
return fmt.Sprintf("%s", revision)
|
||||
return revision
|
||||
}
|
||||
|
||||
return revision
|
||||
|
|
|
@ -72,6 +72,9 @@ func IDByUsernameReply(username string) string {
|
|||
|
||||
responseList := make([]ivrResponse, 0)
|
||||
err = json.NewDecoder(resp.Body).Decode(&responseList)
|
||||
if err != nil {
|
||||
return "xd"
|
||||
}
|
||||
if len(responseList) == 0 {
|
||||
return "xd"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue