Giter VIP home page Giter VIP logo

dgo-paginator's Introduction

Go Reference Go Report Go Version License Version

dgo-paginator

dgo-paginator is a paginator working with buttons. It can be used with interactions and normal messages.

Getting Started

Installing

go get github.com/TopiSenpai/dgo-paginator

Paginator Usage

// create new dgo session
dg, err := discordgo.New("Bot " + token)

// create a new pagination manager
manager := paginator.NewManager()

// register the pagination handler
dg.AddHandler(manager.OnInteractionCreate)

// add a message create handler to spawn a paginator
dg.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
  if m.Author.ID == s.State.User.ID || m.Content != "!test" {
    return
  }

  // your pages can be anything
  pages := []string{
    "page1",
    "page2",
    "page3",
  }
  
  err := manager.CreateMessage(s, m.ChannelID, &paginator.Paginator{
    // the PageFunc is called when a new page is requested put your data per page in here
    PageFunc: func(page int, embed *discordgo.MessageEmbed) {
      embed.Description = pages[page]
    },
    // the max pages this paginator has
    MaxPages:        len(pages),
    // expire after last usage or when created?
    ExpiryLastUsage: true,
  })
  if err != nil {
    fmt.Println(err)
  }
})

// open the session
if err = dg.Open(); err != nil {
  fmt.Println("error opening connection: ", err)
  return
}

// keep the session open
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s

EventCollector Usage

Create a new collector by passing it the discordgo.Session & a filter function. The filter function will be called for every event. If the filter function returns true, the event will be collected and passed through the channel. If the filter function returns false, the event will be ignored. If you are done collecting don't forget to close the collector.

eventChannel, stopCollector := event_collector.NewEventCollector(ssession, func(s *discordgo.Session, e *discordgo.MessageCreate) bool {
    return // filter your events here
})

Examples

You can find examples under _examples

Contributing

Contributions are welcomed but for bigger changes please create a discussion.

License

Distributed under the License . See LICENSE for more information.

dgo-paginator's People

Contributors

topi314 avatar jckli avatar amontg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.