serendip

package module
v0.0.0-...-bd0ed15 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

README.md

Serendip Bot

Serendip is a Discord bot that gets random Wikipedia pages. This bot is built using Go and the discordgo library.

Getting Started

The following instructions assume you already have a working Go environment, if not please see this page first.

Creating a new Discord bot

To set up the bot, you will need to have a Discord account and create a new Discord bot. You can follow the instructions in the Discord developer portal to create a new bot and get the bot token.

Running

Before running, set the environment variable SERENDIP_BOT_TOKEN to the bot token obtained in the step above.

git clone https://github.com/tenax66/serendip.git
go build -o main
./main

Usage

Command Command Description
/wiki Fetches a random Wikipedia page and responds with a title of the page, a summary of the page, and a link to the page.

Documentation

Index

Constants

View Source
const ENDPOINT = "https://ja.wikipedia.org/w/api.php"
View Source
const PSLIMIT = "3"

Variables

This section is empty.

Functions

func GenerateRandomArticleMessage

func GenerateRandomArticleMessage() (string, error)

func GenerateSearchResultMessage

func GenerateSearchResultMessage(query string) (string, error)

func GetRandomPage

func GetRandomPage() (int, string, string, error)

get a random page of Wikipedia

func OnSlashCommand

func OnSlashCommand(s *discordgo.Session, i *discordgo.InteractionCreate)

Types

type Page

type Page struct {
	PageID  int    `json:"pageid"`
	NS      int    `json:"ns"`
	Title   string `json:"title"`
	Extract string `json:"extract"`
}

type PageResult

type PageResult struct {
	Query struct {
		Pages map[string]Page `json:"pages"`
	} `json:"query"`
}

A struct for page fetching results

func GetPageContent

func GetPageContent(pageId int) (PageResult, error)

type PrefixSearch

type PrefixSearch struct {
	NS     int    `json:"ns"`
	Title  string `json:"title"`
	PageID int    `json:"pageid"`
}

type SearchContinue

type SearchContinue struct {
	PSOffset int    `json:"psoffset"`
	Continue string `json:"continue"`
}

type SearchResponse

type SearchResponse struct {
	BatchComplete string         `json:"batchcomplete"`
	Continue      SearchContinue `json:"continue"`
	Query         SearchResult   `json:"query"`
}

search results

func SearchArticle

func SearchArticle(query string) (SearchResponse, error)

type SearchResult

type SearchResult struct {
	PrefixSearch []PrefixSearch `json:"prefixsearch"`
}

type WikipediaPage

type WikipediaPage struct {
	Id    int    `json:"id"`
	Title string `json:"title"`
}

A struct for Wikipedia page infomation

type WikipediaRandomResult

type WikipediaRandomResult struct {
	Query struct {
		Random []WikipediaPage `json:"random"`
	} `json:"query"`
}

A struct for parsing results of Wikipedia API

Directories

Path Synopsis
cmd
post command
slash command

Jump to

Keyboard shortcuts

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