mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
delete channel from database
This commit is contained in:
parent
3af6d60641
commit
3f16128812
|
@ -29,5 +29,16 @@ func AddChannel(login string, message twitch.PrivateMessage, app *Application) {
|
|||
|
||||
reply := fmt.Sprintf("Joined channel %s", login)
|
||||
common.Send(message.Channel, reply, app.TwitchClient)
|
||||
|
||||
}
|
||||
|
||||
func DeleteChannel(login string, message twitch.PrivateMessage, app *Application) {
|
||||
err := app.Models.Channels.Delete(login)
|
||||
if err != nil {
|
||||
common.Send(message.Channel, "Something went wrong FeelsBadMan", app.TwitchClient)
|
||||
app.Logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
reply := fmt.Sprintf("Deleted channel %s", login)
|
||||
common.Send(message.Channel, reply, app.TwitchClient)
|
||||
}
|
|
@ -64,6 +64,17 @@ func handleCommand(message twitch.PrivateMessage, app *Application) {
|
|||
AddChannel(cmdParams[1], message, app)
|
||||
return
|
||||
}
|
||||
case "deletechannel":
|
||||
if message.User.ID != "31437432" { // Limit to myself for now.
|
||||
return
|
||||
} else if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided.", app.TwitchClient)
|
||||
return
|
||||
} else {
|
||||
// ()addchannel noemience
|
||||
DeleteChannel(cmdParams[1], message, app)
|
||||
return
|
||||
}
|
||||
case "bttv":
|
||||
if msgLen < 2 {
|
||||
common.Send(target, "Not enough arguments provided. Usage: ()bttv <emote name>", app.TwitchClient)
|
||||
|
|
|
@ -56,3 +56,29 @@ func (c ChannelModel) Get(login string) (*Channel, error) {
|
|||
|
||||
return &channel, nil
|
||||
}
|
||||
|
||||
func (c ChannelModel) Delete(login string) error {
|
||||
// Prepare the statement.
|
||||
query := `
|
||||
DELETE FROM channels
|
||||
WHERE login = $1`
|
||||
|
||||
// Execute the query returning the number of affected rows.
|
||||
result, err := c.DB.Exec(query, login)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check how many rows were affected.
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// We want atleast 1, if it is 0 the entry did not exist.
|
||||
if rowsAffected == 0 {
|
||||
return ErrRecordNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ type Models struct {
|
|||
Channels interface {
|
||||
Insert(channel *Channel) error
|
||||
Get(login string) (*Channel, error)
|
||||
Delete(login string) error
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue