add two command action
This commit is contained in:
		
							parent
							
								
									ed4f415b35
								
							
						
					
					
						commit
						245bdf8c78
					
				@ -3,17 +3,27 @@ package discord
 | 
			
		||||
import (
 | 
			
		||||
	dsmodel "dorisbot/models/discord"
 | 
			
		||||
	pubmodel "dorisbot/models/public"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"log"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Errors
 | 
			
		||||
var (
 | 
			
		||||
	ErrCheckServer    = errors.New("check server info fail")
 | 
			
		||||
	ErrServerExists   = errors.New("server already exists")
 | 
			
		||||
	ErrCreateServer   = errors.New("create server fail")
 | 
			
		||||
	ErrGetServerOwner = errors.New("get server owner fail")
 | 
			
		||||
	ErrWriteServer    = errors.New("write server data fail")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func addServer(info EvtInfo, name string) string {
 | 
			
		||||
	exists, err := dsmodel.GetServerByID(info.Server)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Println("check server exists fail :: ", err)
 | 
			
		||||
		return "check server info fail"
 | 
			
		||||
		return ErrCheckServer
 | 
			
		||||
	}
 | 
			
		||||
	if exists != nil {
 | 
			
		||||
		return "server already setup"
 | 
			
		||||
		return ErrServerExists
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ds, err := dsmodel.NewServer(info.Server, name, 0)
 | 
			
		||||
@ -133,3 +143,66 @@ func delFacebookPage(info EvtInfo, fbid string) string {
 | 
			
		||||
 | 
			
		||||
	return "Success"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func addInstagram(info EvtInfo, igid, tmpl string) string {
 | 
			
		||||
	log.Printf("add instagram :: ID: %v , tmpl: %v\n", igid, tmpl)
 | 
			
		||||
	if len(igid) == 0 || len(tmpl) == 0 {
 | 
			
		||||
		return "id or tmpl is empty"
 | 
			
		||||
	}
 | 
			
		||||
	ch, err := dsmodel.GetChannelByID(info.Channel)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "get channel data fail"
 | 
			
		||||
	}
 | 
			
		||||
	ig, err := pubmodel.GetInstagramByID(igid)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "get instagram data fail"
 | 
			
		||||
	}
 | 
			
		||||
	if ig == nil {
 | 
			
		||||
		ig, err = pubmodel.NewInstagram(igid)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "create instagram fail"
 | 
			
		||||
		}
 | 
			
		||||
		err = ig.Write()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "write instagram data fail"
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		rt, err := dsmodel.CreateInstagramRT(ch.ID, igid, tmpl)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "create channel instagram link fail"
 | 
			
		||||
		}
 | 
			
		||||
		if err = rt.Write(); err != nil {
 | 
			
		||||
			return "write instagram link data fail"
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		igrt, err := ch.GetInstagramByID(igid)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "get instagram rt fail"
 | 
			
		||||
		}
 | 
			
		||||
		if igrt != nil {
 | 
			
		||||
			return "instagram already linked"
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		rt, err := dsmodel.CreateInstagramRT(ch.ID, igid, tmpl)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "create channel instagram link fail"
 | 
			
		||||
		}
 | 
			
		||||
		if err := rt.Write(); err != nil {
 | 
			
		||||
			return "write instagram link data fail"
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return "Success"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func delInstagram(info EvtInfo, igid string) string {
 | 
			
		||||
	ch, err := dsmodel.GetChannelByID(info.Channel)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "get channel data fail"
 | 
			
		||||
	}
 | 
			
		||||
	err = ch.DeleteInstagram(igid)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "delete instagram data fail"
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return "Success"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user