Advertisement
lfed255-dev

Paste From Computer

Aug 12th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. type GuildController struct {
  2. bc BasicController
  3. }
  4.  
  5. func (this *GuildController) Init() error {
  6. // this.bc.ApiFuncs = make(map[string]UnifuncInst)
  7. // this.bc.DefApiFunc("send",[]string{
  8. // "bot",
  9. // "chid",
  10. // "msg",
  11. // },this.bc.SendFunc)
  12. return nil
  13. }
  14.  
  15. func (this *GuildController) RegisterEventHandler(label string,fh EventHandler) bool {
  16. if _, ok := this.bc.Handlers[label]; ok {
  17. return false
  18. }
  19.  
  20. this.bc.Handlers[label] = fh
  21. return true
  22. }
  23. func (this *GuildController) UnregisterEventHandler(label string) bool {
  24. if _, ok := this.bc.Handlers[label]; !ok {
  25. return false
  26. }
  27.  
  28. delete(this.bc.Handlers,label)
  29.  
  30. return true
  31. }
  32.  
  33. func (this *GuildController) GetHandlers() map[string]EventHandler {
  34. return this.bc.Handlers
  35. }
  36.  
  37. func (this *GuildController) Route(bot *Bot, event *Event) {
  38. if event.Class != EventClassGuild {
  39. return
  40. }
  41.  
  42. switch event.Type{
  43. case EventTypeGuildCreate:
  44. log.Println("bot has joined to server")
  45. case EventTypeGuildMemberAdd:
  46. g, e := bot.Conn.Guild((event.Value.(*dsgo.Member)).GuildID)
  47. if e != nil {
  48. log.Panic(e)
  49. }
  50. log.Printf("%v has joined to %v server\n",(event.Value.(*dsgo.Member)).User.Username,g.Name)
  51. case EventTypeGuildMemberRem:
  52. g, e := bot.Conn.Guild((event.Value.(*dsgo.Member)).GuildID)
  53. if e != nil {
  54. log.Panic(e)
  55. }
  56. log.Printf("%v was left from %v server\n",(event.Value.(*dsgo.Member)).User.Username,g.Name)
  57. }
  58.  
  59.  
  60. }
  61.  
  62. func (this *GuildController) DefApiFunc(name string, argsns []string,inst func(map[string]interface{}) []interface{}) {
  63. this.bc.ApiFuncs[name] = UnifuncInst {
  64. args: argsns,
  65. inst: inst,
  66. }
  67. }
  68.  
  69. func (this *GuildController) DoApiFunc(name string,argsv ...interface{}) []interface{} {
  70. args := make(map[string]interface{})
  71. for i,cname := range this.bc.ApiFuncs[name].args {
  72. args[cname] = argsv[i]
  73. }
  74. return this.bc.ApiFuncs[name].inst(args)
  75. }
  76.  
  77. func (this *GuildController) UndefApiFunc(name string) bool {
  78. if _, ok := this.bc.Handlers[name]; !ok {
  79. return false
  80. }
  81.  
  82. delete(this.bc.Handlers,name)
  83. return true
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement