-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
120 lines (112 loc) · 3.33 KB
/
structs.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
package papaBot
// All structures used by bot (sans extensions and transports).
import (
"database/sql"
"github.com/pelletier/go-toml"
"github.com/sirupsen/logrus"
"net/http"
"regexp"
"time"
"github.com/pawelszydlo/humanize"
"github.com/pawelszydlo/papa-bot/events"
"github.com/pawelszydlo/papa-bot/transports"
)
// Bot itself.
type Bot struct {
// Was initialization complete?
initDone bool
// Database connection.
Db *sql.DB
// HTTP client.
HTTPClient *http.Client
// Logger.
Log *logrus.Logger
// Event dispatcher instance.
EventDispatcher *events.EventDispatcher
// Full config file tree.
fullConfig *toml.Tree
// Full texts file tree.
fullTexts *toml.Tree
// Bot's configuration.
Config *Configuration
// Bot texts struct.
Texts *botTexts
// Values humanizer.
Humanizer *humanize.Humanizer
// Currently authenticated users.
authenticatedUsers map[string]string
authenticatedAdmins map[string]string
authenticatedOwners map[string]string
// Registered bot commands.
commands map[string]*BotCommand
// Number of uses per command.
commandUseLimit map[string]int
// Was the warning sent, per command.
commandWarn map[string]bool
// Commands that will not have their params listed in the logs (auth etc.)
commandsHideParams map[string]bool
// Custom variables for use in extensions.
customVars map[string]string
// Registered bot extensions,
extensions []extension
// Enabled transports.
Transports map[string]transports.Transport
// Time when URL info was last announced, per channel + link.
lastURLAnnouncedTime map[string]time.Time
// Lines passed since URL info was last announced, per channel + link.
lastURLAnnouncedLinesPassed map[string]int
// More information to give about last link, per channel.
urlMoreInfo map[string]string
// Time for next daily tick.
nextDailyTick time.Time
// Regular expression for extracting sample text from website.
webContentSampleRe *regexp.Regexp
}
// Interface representing an extension.
type extension interface {
Init(bot *Bot) error
}
// Bot's commands.
type BotCommand struct {
// Names of the command (main and aliases).
CommandNames []string
// Does this command require private query?
Private bool
// This command can only be run by the owner?
Owner bool
// This command can only be run by an admin?
Admin bool
// Help string showing possible parameters.
HelpParams string
// Help string with the description.
HelpDescription string
// Function to be executed.
CommandFunc func(bot *Bot, sourceEvent *events.EventMessage, params []string)
}
// Bot's configuration. It will be loaded from the provided file on New(), overwriting any defaults.
type Configuration struct {
Name string
Language string
ChatLogging bool
CommandsPer5 int
UrlAnnounceIntervalMinutes time.Duration
UrlAnnounceIntervalLines int
PageBodyMaxSize uint
HttpDefaultUserAgent string
DailyTickHour int
DailyTickMinute int
LogLevel logrus.Level
}
// Bot's core texts.
type botTexts struct {
NeedsPriv string
NeedsAdmin string
PasswordOk string
SearchResults string
SearchNoResults string
SearchPrivateNotice string
CommandLimit string
NothingToAdd string
WrongCommand []string
SeeHelp string
}