reddit

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: MIT Imports: 6 Imported by: 0

README

Reddit Usage

Ensure that you have already navigated to your GOPATH and installed the following packages:

  • go get -u github.com/nikoksr/notify

Steps for Reddit notifications

These are general and very high level instructions

  1. Log into Reddit create a new "script" type by visiting here
  2. The "redirect uri" parameter doesn't matter in this case and can just be set to http://localhost:8080
  3. Copy the client id and client secret for usage below
  4. Now you should be good to use the code detailed in doc.go

NOTE: You may have difficulties using your user's password if you have 2FA enabled. You can disable it by going here but be aware of the security implications and ensure you have a strong password set.

Documentation

Overview

Package reddit implements a Reddit notifier, allowing messages to be sent to multiple recipients

Usage:

package main

import (
	"context"

	"github.com/nikoksr/notify"
	"github.com/nikoksr/notify/service/reddit"
)

func main() {

	notifier := notify.New()

	// Provide your Reddit app credentials and username/password
	redditService := reddit.New("clientID", "clientSecret", "username", "password")

	// Pass the usernames for where to send the messages
	pushoverService.AddReceivers("User1", "User2")

	// Tell our notifier to use the Reddit service. You can repeat the above process
	// for as many services as you like and just tell the notifier to use them.
	notifier.UseServices(redditService)

	// Send a message
	_ = notifier.Send(
		context.Background(),
		"Hello!",
		"I am a bot written in Go!",
	)
}

Package reddit implements a Reddit notifier, allowing messages to be sent to multiple recipients

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reddit

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

Reddit struct holds necessary data to communicate with the Reddit API.

func New

func New(clientID, clientSecret, username, password string) (*Reddit, error)

New returns a new instance of a Reddit notification service. For more information on obtaining client credentials:

-> https://github.com/reddit-archive/reddit/wiki/OAuth2

func (*Reddit) AddReceivers

func (r *Reddit) AddReceivers(recipients ...string)

AddReceivers takes Reddit usernames and adds them to the internal recipient list. The Send method will send a given message to all of those users.

func (*Reddit) Send

func (r *Reddit) Send(ctx context.Context, subject, message string) error

Send takes a message subject and a message body and sends them to all previously set recipients.

Jump to

Keyboard shortcuts

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