-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added middleware features into package bot. (#3)
* Middleware nameflag * Completed M-Middleware feature * Changed Namer/Descriptor API to CanSetup API
- Loading branch information
1 parent
09d8c5b
commit aadcbd0
Showing
12 changed files
with
459 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/diamondburned/arikawa/bot" | ||
"github.com/diamondburned/arikawa/gateway" | ||
) | ||
|
||
// Flag for administrators only. | ||
type Debug struct { | ||
Context *bot.Context | ||
} | ||
|
||
// Setup demonstrates the CanSetup interface. This function will never be parsed | ||
// as a callback of any event. | ||
func (d *Debug) Setup(sub *bot.Subcommand) { | ||
// Set a custom command (e.g. "!go ..."): | ||
sub.Command = "go" | ||
// Set a custom description: | ||
sub.Description = "Print Go debugging variables" | ||
|
||
// Manually set the usage for each function. | ||
|
||
sub.ChangeCommandInfo("GOOS", "", | ||
"Prints the current operating system") | ||
|
||
sub.ChangeCommandInfo("GC", "", | ||
"Triggers the garbage collecto") | ||
|
||
sub.ChangeCommandInfo("Goroutines", "", | ||
"Prints the current number of Goroutines") | ||
} | ||
|
||
// ~go goroutines | ||
func (d *Debug) Goroutines(m *gateway.MessageCreateEvent) error { | ||
_, err := d.Context.SendMessage(m.ChannelID, fmt.Sprintf( | ||
"goroutines: %d", | ||
runtime.NumGoroutine(), | ||
), nil) | ||
return err | ||
} | ||
|
||
// ~go GOOS | ||
func (d *Debug) RーGOOS(m *gateway.MessageCreateEvent) error { | ||
_, err := d.Context.SendMessage( | ||
m.ChannelID, strings.Title(runtime.GOOS), nil) | ||
return err | ||
} | ||
|
||
// ~go GC | ||
func (d *Debug) RーGC(m *gateway.MessageCreateEvent) error { | ||
runtime.GC() | ||
|
||
_, err := d.Context.SendMessage(m.ChannelID, "Done.", nil) | ||
return err | ||
} | ||
|
||
// ~go die | ||
// This command will be hidden from ~help by default. | ||
func (d *Debug) AーDie(m *gateway.MessageCreateEvent) error { | ||
log.Fatalln("User", m.Author.Username, "killed the bot x_x") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# What happened here? | ||
|
||
We've moved everything to https://github.com/diamondburned/ak-rfrouter, as this | ||
package will be replaced with a [go-chi](https://github.com/go-chi/chi) style router. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.