Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reddit grabber function & techgore command #11

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/aerial/aerial.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func main() {
a.cs.AddCmd("time", "shows the current bot time", bot.NoPermissions, curTime)
a.cs.AddCmd("streams", "shows the different Ponyville FM stream links", bot.NoPermissions, streams)
a.cs.AddCmd("derpi", "grabs a random (safe) image from Derpibooru with the given search results", bot.NoPermissions, derpi)
a.cs.AddCmd("techgore", "grabs a random post from /r/techsupportgore for your viewing pleasure", bot.NoPermissions, techgore)

dg.AddHandler(a.Handle)
dg.AddHandler(pesterLink)
Expand Down
17 changes: 17 additions & 0 deletions cmd/aerial/pvfm.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func streams(s *discordgo.Session, m *discordgo.Message, parv []string) error {
}

func derpi(s *discordgo.Session, m *discordgo.Message, parv []string) error {
if m.ChannelID != "292755043684450304" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this a configuration setting using an environment variable.

s.ChannelMessageSend(m.ChannelID, "Please use this command only in #diabeetus")
return nil
}
searchResults, err := derpiSearch.SearchDerpi(m.Content[7:len(m.Content)])
if err != nil {
s.ChannelMessageSend(m.ChannelID, "An error occured.")
Expand All @@ -236,3 +240,16 @@ func derpi(s *discordgo.Session, m *discordgo.Message, parv []string) error {
s.ChannelMessageSend(m.ChannelID, "http:"+searchResults.Search[randomRange(0, len(searchResults.Search))].Image)
return nil
}

func techgore(s *discordgo.Session, m *discordgo.Message, parv []string) error {
if m.ChannelID != "193740418633039872" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this a configuration setting using an environment variable.

s.ChannelMessageSend(m.ChannelID, "Please use this command only in #nerdery")
return nil // only works in #nerdery
}
results, err := redditSearch("techsupportgore")
if err != nil {
return err
}
s.ChannelMessageSend(m.ChannelID, results[randomRange(0, len(results))].URL)
return nil
}
15 changes: 15 additions & 0 deletions cmd/aerial/reddit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import "github.com/jzelinskie/geddit"

func redditSearch(subreddit string) ([]*geddit.Submission, error) {
listOptions := geddit.ListingOptions{
Limit: 50,
}
reddit := geddit.NewSession("discordbot")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/reddit/reddit/wiki/API#rules

Prefer something like

const (
	appid = "github.com/PonyvilleFM/aura/cmd/aerial"
	version = "0.1"
)

userAgent := fmt.Sprintf(
	"%s on %s %s:%s:%s (by /u/shadowh511)",
	runtime.Version(), runtime.GOOS, runtime.GOARCH,
	appid, version,
)

results, err := reddit.SubredditSubmissions(subreddit, geddit.NewSubmissions, listOptions)
if err != nil {
return nil, err
}
return results, nil
}
61 changes: 61 additions & 0 deletions vendor/github.com/beefsack/go-rate/rate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions vendor/github.com/jzelinskie/geddit/comment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading