Awaiter

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 1 Imported by: 0

README

Awaiter

A Discordgo helper allowing for the use of AwaiteMessages(channelId) like thing

Usage

package main

import (
    "fmt"
    "github.com/Jviguy/Awaiter"
    "github.com/bwmarrin/discordgo"
    "os"
)

var awaiter *Awaiter.MessageSendAwaiter

func main() {
  	// Create a new Discord session using the provided bot token.
	dg, err := discordgo.New("Bot " + Token)
	if err != nil {
		fmt.Println("error creating Discord session,", err)
		return
	}

	// Register the messageCreate func as a callback for MessageCreate events.
	dg.AddHandler(messageCreate)
  
    awaiter = Awaiter.NewMessageSendAwaiter(dg)
  
	// In this example, we only care about receiving message events.
	dg.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsGuildMessages)

	// Open a websocket connection to Discord and begin listening.
	err = dg.Open()
	if err != nil {
		fmt.Println("error opening connection,", err)
		return
	}

	// Wait here until CTRL-C or other term signal is received.
	fmt.Println("Bot is now running.  Press CTRL-C to exit.")
	sc := make(chan os.Signal, 1)
	signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
	<-sc

	// Cleanly close down the Discord session.
	dg.Close()
}
// This function will be called (due to AddHandler above) every time a new
// message is created on any channel that the authenticated bot has access to.
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
	// Ignore all messages created by the bot itself
	// This isn't required in this specific example but it's a good practice.
	if m.Author.ID == s.State.User.ID {
		return
	}
	// If the message is "!awaitMessage" log the next message
	if m.Content == "!awaitMessage" {
    //await a new message
    msg := awaiter.AwaitMessage(m.ChannelId,false)
    //print it
    fmt.Println(msg.Content)
  }
}

Documentation

Overview

A package for DiscordGo for awaiting Certain Events to happen In Certain Channels

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Awaiter

type Awaiter interface {
	GetSession() *discordgo.Session
	RemoveEntry(k int)
}

type Entry

type Entry interface {
	GetChannelId() string

	IncludeBots() bool
}

The base Entry type which is "overloaded" for each independent awaiter

type MessageDeleteAwaiter

type MessageDeleteAwaiter struct {

	//The *discordgo.Session this awaiter belongs to
	Entries []MessageDeleteEntry
	// contains filtered or unexported fields
}

An Awaiter for awaiting messages to be sent in a said channel

func NewMessageDeleteAwaiter

func NewMessageDeleteAwaiter(s *discordgo.Session) *MessageDeleteAwaiter

Initializes a new MessageDeleteAwaiter ready for use

func (*MessageDeleteAwaiter) Await

func (m *MessageDeleteAwaiter) Await(entry MessageDeleteEntry)

Adds a Entry to the MessageDeleteAwaiter and has to be manually handled.

func (*MessageDeleteAwaiter) AwaitDeletedMessage

func (m *MessageDeleteAwaiter) AwaitDeletedMessage(channelId string, IncludeBots bool) *discordgo.Message

Adds a Entry to the MessageDeleteAwaiter and returns the message when it is received.

func (*MessageDeleteAwaiter) GetSession

func (m *MessageDeleteAwaiter) GetSession() *discordgo.Session

Returns the *discordgo.Session that the Awaiter has been added to.

func (*MessageDeleteAwaiter) RemoveEntry

func (m *MessageDeleteAwaiter) RemoveEntry(k int)

Removes a Entry from a MessageDeleteAwaiter

type MessageDeleteEntry

type MessageDeleteEntry struct {
	// contains filtered or unexported fields
}

A Entry for the MessageSendAwaiter

func (*MessageDeleteEntry) GetChannel

func (m *MessageDeleteEntry) GetChannel() chan *discordgo.Message

Returns the channel that will be returned too

func (*MessageDeleteEntry) GetChannelId

func (m *MessageDeleteEntry) GetChannelId() string

inherited from Entry and returns the ChannelId used in the Entry

func (*MessageDeleteEntry) IncludeBots

func (m *MessageDeleteEntry) IncludeBots() bool

type MessageEntry added in v1.0.2

type MessageEntry interface {
	GetMessageId() string

	IncludeBots() bool
}

type MessageReactionAddAwaiter added in v1.0.2

type MessageReactionAddAwaiter struct {
	//A slice of Entries belonging to this Awaiter
	Entries []MessageReactionAddEntry
	// contains filtered or unexported fields
}

func (*MessageReactionAddAwaiter) GetSession added in v1.0.2

func (m *MessageReactionAddAwaiter) GetSession() *discordgo.Session

func (*MessageReactionAddAwaiter) RemoveEntry added in v1.0.2

func (m *MessageReactionAddAwaiter) RemoveEntry(k int)

type MessageReactionAddEntry added in v1.0.2

type MessageReactionAddEntry struct {
	// contains filtered or unexported fields
}

func (MessageReactionAddEntry) GetChannel added in v1.0.2

func (MessageReactionAddEntry) GetMessageId added in v1.0.2

func (m MessageReactionAddEntry) GetMessageId() string

func (MessageReactionAddEntry) IncludeBots added in v1.0.2

func (m MessageReactionAddEntry) IncludeBots() bool

type MessageSendAwaiter

type MessageSendAwaiter struct {

	//A slice of Entries belonging to this Awaiter
	Entries []MessageSendEntry
	// contains filtered or unexported fields
}

An Awaiter for awaiting messages to be sent in a said channel

func NewMessageSendAwaiter

func NewMessageSendAwaiter(s *discordgo.Session) *MessageSendAwaiter

Initializes a new MessageSendAwaiter ready for use

func (*MessageSendAwaiter) Await

func (m *MessageSendAwaiter) Await(entry MessageSendEntry)

Adds a Entry to the MessageSendAwaiter and has to be manually handled.

func (*MessageSendAwaiter) AwaitMessage

func (m *MessageSendAwaiter) AwaitMessage(channelId string, IncludeBots bool) *discordgo.MessageCreate

Adds a Entry to the MessageSendAwaiter and returns the message when it is received.

func (*MessageSendAwaiter) GetSession

func (m *MessageSendAwaiter) GetSession() *discordgo.Session

Returns the *discordgo.Session that the Awaiter has been added to.

func (*MessageSendAwaiter) RemoveEntry

func (m *MessageSendAwaiter) RemoveEntry(k int)

Removes a Entry from a MessageSendAwaiter

type MessageSendEntry

type MessageSendEntry struct {
	// contains filtered or unexported fields
}

A Entry for the MessageSendAwaiter

func (MessageSendEntry) GetChannel

func (m MessageSendEntry) GetChannel() chan *discordgo.MessageCreate

Returns the channel that will be returned too

func (MessageSendEntry) GetChannelId

func (m MessageSendEntry) GetChannelId() string

inherited from Entry and returns the ChannelId used in the Entry

func (MessageSendEntry) IncludeBots

func (m MessageSendEntry) IncludeBots() bool

Returns wether to include bots in the await

Jump to

Keyboard shortcuts

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