Documentation ¶
Index ¶
- Variables
- func BotAllowed(pageContent string) bool
- func CanEdit() bool
- func CreateAndAuthenticateClient(maxlag mwclient.Maxlag) *mwclient.Client
- func EditLimit() bool
- func FetchWikitext(pageID string) (content string, err error)
- func FetchWikitextFromTitle(pageTitle string) (content string, err error)
- func FetchWikitextFromTitleWithTimestamps(pageTitle string) (content string, revtimestamp string, curtimestamp string, err error)
- func FetchWikitextWithTimestamps(pageID string) (content string, revtimestamp string, curtimestamp string, err error)
- func ForPageInQuery(parameters params.Values, callback PageInQueryCallback)
- func GetCategorisationTimestampFromPage(page *jason.Object, category string) (timestamp string)
- func GetContentFromPage(page *jason.Object) (content string, err error)
- func GetMainSlotFromRevision(revision *jason.Object) (string, error)
- func GetPagesFromQuery(resp *jason.Object) []*jason.Object
- func GetThingFromQuery(resp *jason.Object, thing string) ([]*jason.Object, error)
- func LoadJSONFromPageID(pageID string) *jason.Object
- func LoadJSONFromPageTitle(pageTitle string) *jason.Object
- func NoMaxlagDo(f NoMaxlagFunction, w *mwclient.Client) error
- func PanicErr(v ...interface{})
- func ParseTaskConfig(cobj interface{})
- func SaveEditLimit()
- func SerializeToJSON(serializable interface{}) string
- func SetupBot(s BotSettings)
- type BotSettings
- type NoMaxlagFunction
- type PageInQueryCallback
Constants ¶
This section is empty.
Variables ¶
var DefaultMaxlag mwclient.Maxlag = mwclient.Maxlag{ On: true, Timeout: "5", Retries: 3, }
DefaultMaxlag is a Maxlag representing sensible defaults for any non-urgent task being run by a Yapperbot.
var NoMaxlag mwclient.Maxlag = mwclient.Maxlag{ On: true, Timeout: "5", Retries: 3, }
NoMaxlag is a Maxlag for urgent tasks, where maxlag must be disabled.
Functions ¶
func BotAllowed ¶
BotAllowed take a page content and determines if the botUser is allowed to edit the page per the applicable templates.
func CanEdit ¶
func CanEdit() bool
CanEdit checks if the task has been killed, and then checks if the bot is edit limited. This *must* be used for all edits apart from those which only affect the bot's own userspace, or those which must run even if the task is killed (e.g. updating JSON files which describe the run which was just done).
func CreateAndAuthenticateClient ¶
func CreateAndAuthenticateClient(maxlag mwclient.Maxlag) *mwclient.Client
CreateAndAuthenticateClient uses the details already passed into ybtools in setup.go to return a fully-authenticated mwclient
func EditLimit ¶
func EditLimit() bool
EditLimit can be called to increment the current edit count Returns true if allowed to edit or false if not Remember to call SaveEditLimit at the end of the program if using this!
func FetchWikitext ¶
FetchWikitext takes a pageId and gets the wikitext of that page. The default functionality in the library does not work for this in my experience; it just returns an empty string for some reason. So we're rolling our own!
func FetchWikitextFromTitle ¶
FetchWikitextFromTitle takes a title and gets the wikitext of that page.
func FetchWikitextFromTitleWithTimestamps ¶
func FetchWikitextFromTitleWithTimestamps(pageTitle string) (content string, revtimestamp string, curtimestamp string, err error)
FetchWikitextFromTitleWithTimestamps takes a title and gets the wikitext of that page, also returning the revision timestamp and the current timestamp.
func FetchWikitextWithTimestamps ¶
func FetchWikitextWithTimestamps(pageID string) (content string, revtimestamp string, curtimestamp string, err error)
FetchWikitextWithTimestamps takes a pageId and gets the wikitext of that page, also returning the revision timestamp and the current timestamp.
func ForPageInQuery ¶
func ForPageInQuery(parameters params.Values, callback PageInQueryCallback)
ForPageInQuery takes parameters and a callback function. It then queries using the parameters it is given, and calls the callback function for every page in the query response.
func GetCategorisationTimestampFromPage ¶
GetCategorisationTimestampFromPage takes a page, and gets the timestamp at which the page was categorised. All the errors in this function are Fatal, because frankly, if something's gone wrong with the timestamp reading, we're not really going to be able to run the algorithm correctly anyway.
func GetContentFromPage ¶
GetContentFromPage turns a *jason.Object for a Page into the main slot content, and/or an applicable error.
Yes, there is a function to do this already in the library (GetPagesByName). No, I don't want to use it. Why? We've already got the page content here - making another request to get it again is wasteful when we could just locally parse what we already have.
func GetMainSlotFromRevision ¶
GetMainSlotFromRevision fetches the main slot content, given a revision object formatted per the MediaWiki Action API JSON.
func GetPagesFromQuery ¶
GetPagesFromQuery takes a query and returns an array of Pages. Convenience wrapper for GetThingFromQuery.
func GetThingFromQuery ¶
GetThingFromQuery takes a query and a key that's being looked for, and returns the inner thing array.
func LoadJSONFromPageID ¶
LoadJSONFromPageID takes a pageID, then loads and deserializes the contained JSON. It returns the deserialised JSON in a jason.Object pointer.
func LoadJSONFromPageTitle ¶
LoadJSONFromPageTitle takes a title string, then loads and deserializes the contained JSON. It returns the deserialised JSON in a jason.Object pointer.
func NoMaxlagDo ¶
func NoMaxlagDo(f NoMaxlagFunction, w *mwclient.Client) error
NoMaxlagDo takes a function which returns an error (or nil), and an mwclient pointer, than executes that function with no maxlag. It returns the same return as the NoMaxlagFunction it's passed.
func PanicErr ¶
func PanicErr(v ...interface{})
PanicErr panics the program with a specified message, also sending a message to the tool inbox on Toolforge explaining the issue.
func ParseTaskConfig ¶
func ParseTaskConfig(cobj interface{})
ParseTaskConfig takes in a pointer to a config object and populates the config object with the task configuration
func SaveEditLimit ¶
func SaveEditLimit()
SaveEditLimit saves the current edit limit to the edit limit file, assuming that there is an edit limit usage to save This function must be called at the end of the program for edit limiting to work
func SerializeToJSON ¶
func SerializeToJSON(serializable interface{}) string
SerializeToJSON takes in any serializable object and returns the serialized JSON string
func SetupBot ¶
func SetupBot(s BotSettings)
SetupBot sets the bot name, ready for future calls to BotAllowed.
Types ¶
type BotSettings ¶
BotSettings is a struct storing all the information about the bot needed to make the tools library work.
type NoMaxlagFunction ¶
type NoMaxlagFunction func() error
NoMaxlagFunction is the definition of a function accepted by NoMaxlagDo; it's just a function with no parameters that returns an error.
type PageInQueryCallback ¶
type PageInQueryCallback func(pageTitle, pageContent, revTS, curTS string)
PageInQueryCallback is a function used as a callback for ForPageInQuery.