Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type GuildController struct {
- bc BasicController
- }
- func (this *GuildController) Init() error {
- // this.bc.ApiFuncs = make(map[string]UnifuncInst)
- // this.bc.DefApiFunc("send",[]string{
- // "bot",
- // "chid",
- // "msg",
- // },this.bc.SendFunc)
- return nil
- }
- func (this *GuildController) RegisterEventHandler(label string,fh EventHandler) bool {
- if _, ok := this.bc.Handlers[label]; ok {
- return false
- }
- this.bc.Handlers[label] = fh
- return true
- }
- func (this *GuildController) UnregisterEventHandler(label string) bool {
- if _, ok := this.bc.Handlers[label]; !ok {
- return false
- }
- delete(this.bc.Handlers,label)
- return true
- }
- func (this *GuildController) GetHandlers() map[string]EventHandler {
- return this.bc.Handlers
- }
- func (this *GuildController) Route(bot *Bot, event *Event) {
- if event.Class != EventClassGuild {
- return
- }
- switch event.Type{
- case EventTypeGuildCreate:
- log.Println("bot has joined to server")
- case EventTypeGuildMemberAdd:
- g, e := bot.Conn.Guild((event.Value.(*dsgo.Member)).GuildID)
- if e != nil {
- log.Panic(e)
- }
- log.Printf("%v has joined to %v server\n",(event.Value.(*dsgo.Member)).User.Username,g.Name)
- case EventTypeGuildMemberRem:
- g, e := bot.Conn.Guild((event.Value.(*dsgo.Member)).GuildID)
- if e != nil {
- log.Panic(e)
- }
- log.Printf("%v was left from %v server\n",(event.Value.(*dsgo.Member)).User.Username,g.Name)
- }
- }
- func (this *GuildController) DefApiFunc(name string, argsns []string,inst func(map[string]interface{}) []interface{}) {
- this.bc.ApiFuncs[name] = UnifuncInst {
- args: argsns,
- inst: inst,
- }
- }
- func (this *GuildController) DoApiFunc(name string,argsv ...interface{}) []interface{} {
- args := make(map[string]interface{})
- for i,cname := range this.bc.ApiFuncs[name].args {
- args[cname] = argsv[i]
- }
- return this.bc.ApiFuncs[name].inst(args)
- }
- func (this *GuildController) UndefApiFunc(name string) bool {
- if _, ok := this.bc.Handlers[name]; !ok {
- return false
- }
- delete(this.bc.Handlers,name)
- return true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement