-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
149 lines (131 loc) · 4.52 KB
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package sqlitestorage
import (
"fmt"
"time"
"github.com/torlenor/redseligg/storagemodels"
)
// GetQuotesPluginQuote returns a QuotesPluginQuote.
func (b *SQLiteStorage) GetQuotesPluginQuote(botID, pluginID, identifier string) (storagemodels.QuotesPluginQuote, error) {
row, err := b.db.Query(
fmt.Sprintf(`SELECT * FROM %s WHERE bot_id="%s" AND plugin_id="%s" and identifier="%s"`,
tableQuotesPluginQuote,
botID,
pluginID,
identifier))
if err != nil {
return storagemodels.QuotesPluginQuote{}, err
}
defer row.Close()
quote := storagemodels.QuotesPluginQuote{}
for row.Next() {
var id int
var gotBotID string
var gotPluginID string
var gotIdentifier string
row.Scan(&id, &gotBotID, &gotPluginID, &gotIdentifier, "e.Author, "e.Added, "e.AuthorID, "e.ChannelID, "e.Text)
}
return quote, nil
}
// GetQuotesPluginQuotesList returns a QuotesPluginQuotesList.
func (b *SQLiteStorage) GetQuotesPluginQuotesList(botID, pluginID, identifier string) (storagemodels.QuotesPluginQuotesList, error) {
row, err := b.db.Query(
fmt.Sprintf(`SELECT identifier FROM %s WHERE bot_id="%s" AND plugin_id="%s"`,
tableQuotesPluginQuote,
botID,
pluginID))
if err != nil {
return storagemodels.QuotesPluginQuotesList{}, err
}
defer row.Close()
quotes := storagemodels.QuotesPluginQuotesList{}
for row.Next() {
var gotIdentifier string
row.Scan(&gotIdentifier)
quotes.UUIDs = append(quotes.UUIDs, gotIdentifier)
}
return quotes, nil
}
// GetTimedMessagesPluginMessages returns a TimedMessagesPluginMessages.
func (b *SQLiteStorage) GetTimedMessagesPluginMessages(botID, pluginID, identifier string) (storagemodels.TimedMessagesPluginMessages, error) {
row, err := b.db.Query(
fmt.Sprintf(`SELECT * FROM %s WHERE bot_id="%s" AND plugin_id="%s" AND identifier="%s"`,
tableTimedMessagesPluginMessage,
botID,
pluginID,
identifier))
if err != nil {
return storagemodels.TimedMessagesPluginMessages{}, err
}
defer row.Close()
messages := storagemodels.TimedMessagesPluginMessages{}
for row.Next() {
var id int
var gotBotID string
var gotPluginID string
var gotIdentifier string
var gotInterval int64
message := storagemodels.TimedMessagesPluginMessage{}
err := row.Scan(&id, &gotBotID, &gotPluginID, &gotIdentifier, &message.Text, &gotInterval, &message.ChannelID, &message.LastSent)
if err != nil {
b.log.Errorf("Error parsing SQLite select: %s", err)
continue
}
message.Interval = time.Millisecond * time.Duration(gotInterval)
messages.Messages = append(messages.Messages, message)
}
return messages, nil
}
// GetCustomCommandsPluginCommands returns CustomCommandsPluginCommands.
func (b *SQLiteStorage) GetCustomCommandsPluginCommands(botID, pluginID, identifier string) (storagemodels.CustomCommandsPluginCommands, error) {
row, err := b.db.Query(
fmt.Sprintf(`SELECT * FROM %s WHERE bot_id="%s" AND plugin_id="%s" AND identifier="%s"`,
tableCustomCommandsPluginCommands,
botID,
pluginID,
identifier))
if err != nil {
return storagemodels.CustomCommandsPluginCommands{}, err
}
defer row.Close()
commands := storagemodels.CustomCommandsPluginCommands{}
for row.Next() {
var id int
var gotBotID string
var gotPluginID string
var gotIdentifier string
command := storagemodels.CustomCommandsPluginCommand{}
err := row.Scan(&id, &gotBotID, &gotPluginID, &gotIdentifier, &command.Command, &command.Text, &command.ChannelID)
if err != nil {
b.log.Errorf("Error parsing SQLite select: %s", err)
continue
}
commands.Commands = append(commands.Commands, command)
}
return commands, nil
}
// GetRssPluginSubscriptions returns a RssPluginSubscriptions.
func (b *SQLiteStorage) GetRssPluginSubscriptions(botID, pluginID string) (storagemodels.RssPluginSubscriptions, error) {
row, err := b.db.Query(
fmt.Sprintf(`SELECT * FROM %s WHERE bot_id="%s" AND plugin_id="%s"`,
tableRssPluginSubscription,
botID,
pluginID))
if err != nil {
return storagemodels.RssPluginSubscriptions{}, err
}
defer row.Close()
subscriptions := storagemodels.RssPluginSubscriptions{}
for row.Next() {
var id int
var gotBotID string
var gotPluginID string
subscription := storagemodels.RssPluginSubscription{}
err := row.Scan(&id, &gotBotID, &gotPluginID, &subscription.Identifier, &subscription.Link, &subscription.ChannelID, &subscription.LastPostedPubDate)
if err != nil {
b.log.Errorf("Error parsing SQLite select: %s", err)
continue
}
subscriptions.Subscriptions = append(subscriptions.Subscriptions, subscription)
}
return subscriptions, nil
}