-
Notifications
You must be signed in to change notification settings - Fork 3
/
feedback.go
78 lines (65 loc) · 2.59 KB
/
feedback.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
package main
//
// Yapperbot-FRS, the Feedback Request Service bot for Wikipedia
// Copyright (C) 2020 Naypta
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
import (
"log"
"math/rand"
"yapperbot-frs/src/frslist"
"yapperbot-frs/src/messages"
"yapperbot-frs/src/rfc"
"cgt.name/pkg/go-mwclient"
)
const maxMsgsToSend int = 15
const minMsgsToSend int = 5
// requestFeedbackFor takes an object that implements frsRequesting and a mwclient instance,
// and processes the feedback request for the frsRequesting object.
func requestFeedbackFor(requester frsRequesting, w *mwclient.Client) {
// msgsToSend is a randomly-selected number of messages we want to send out.
// it evaluates out to any number between max and min
var msgsToSend int = (rand.Intn(maxMsgsToSend-minMsgsToSend) + minMsgsToSend)
// headersToSendTo will be our slice of headers that we want to consider users in.
// it's important that this is a separate array, as we later consider its length
var headersToSendTo []string
// allHeader is the header that's "catch all" for all RfCs/GA noms/whatever, where applicable
var allHeader string
for _, header := range frslist.GetListHeaders() {
include, isAllHeader := requester.IncludeHeader(header)
if include {
headersToSendTo = append(headersToSendTo, header)
messages.CleanHeader(header)
}
if isAllHeader {
allHeader = header
}
}
var rfcid string
if rfc, isRfC := requester.(rfc.RfC); isRfC {
rfcid = rfc.ID
}
if len(headersToSendTo) > 0 {
users := frslist.GetUsersFromHeaders(headersToSendTo, allHeader, msgsToSend)
for _, user := range users {
messages.QueueMessage(&messages.Message{
User: user,
Type: requester.RequestType(),
Title: requester.PageTitle(),
RFCID: rfcid,
})
log.Println("Queued a message for", user.Username, "to give feedback on", requester.PageTitle(), "in", user.Header)
}
} else {
log.Println("WARNING: Headers to send to returned as less than one for page", requester.PageTitle(), "so ignoring for now, but this could be a bug")
}
}