ybtools

package module
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2020 License: GPL-3.0 Imports: 14 Imported by: 0

README

Yapperbot Tools

A set of imports used by other Wikipedia bots I've created. These probably won't be of much use to anyone else, but you're welcome to them in accordance with the license if you like!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BotAllowed added in v0.1.1

func BotAllowed(pageContent string) bool

BotAllowed take a page content and determines if the botUser is allowed to edit the page per the applicable templates.

func CanEdit added in v1.3.0

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 added in v0.1.6

func CreateAndAuthenticateClient() *mwclient.Client

CreateAndAuthenticateClient uses the details already passed into ybtools in setup.go to return a fully-authenticated mwclient

func EditLimit added in v0.1.5

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

func FetchWikitext(pageID string) (content string, err error)

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 added in v1.2.0

func FetchWikitextFromTitle(pageTitle string) (content string, err error)

FetchWikitextFromTitle takes a title and gets the wikitext of that page.

func GetCategorisationTimestampFromPage

func GetCategorisationTimestampFromPage(page *jason.Object, category string) (timestamp string)

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

func GetContentFromPage(page *jason.Object) (content string, err error)

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 GetPagesFromQuery

func GetPagesFromQuery(resp *jason.Object) []*jason.Object

GetPagesFromQuery takes a query and returns an array of Pages. Convenience wrapper for GetThingFromQuery.

func GetThingFromQuery added in v1.1.0

func GetThingFromQuery(resp *jason.Object, thing string) []*jason.Object

GetThingFromQuery takes a query and a key that's being looked for, and returns the inner thing array.

func LoadJSONFromPageID added in v1.2.0

func LoadJSONFromPageID(pageID string) *jason.Object

LoadJSONFromPageID takes a pageID, then loads and deserializes the contained JSON. It returns the deserialised JSON in a jason.Object pointer.

func LoadJSONFromPageTitle added in v1.2.0

func LoadJSONFromPageTitle(pageTitle string) *jason.Object

LoadJSONFromPageTitle takes a title string, then loads and deserializes the contained JSON. It returns the deserialised JSON in a jason.Object pointer.

func PanicErr added in v1.3.0

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 added in v0.1.6

func ParseTaskConfig(cobj interface{})

ParseTaskConfig takes in a pointer to a config object and populates the config object with the task configuration

func SaveEditLimit added in v0.1.5

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 added in v1.2.0

func SerializeToJSON(serializable interface{}) string

SerializeToJSON takes in any serializable object and returns the serialized JSON string

func SetupBot added in v0.1.1

func SetupBot(taskname string, botuser string)

SetupBot sets the bot name, ready for future calls to BotAllowed.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL