let admins reset default emojis
This commit is contained in:
parent
5bfc5e3e40
commit
32bd1a5e28
|
@ -66,6 +66,7 @@ func init() {
|
||||||
var emojis map[string]string
|
var emojis map[string]string
|
||||||
|
|
||||||
type emojiHolder struct {
|
type emojiHolder struct {
|
||||||
|
NoDefault bool `json:"no_defaults"`
|
||||||
Emojis []map[string]string `json:"emojis"`
|
Emojis []map[string]string `json:"emojis"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,17 +78,22 @@ func InitEmoji() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
emojis = make(map[string]string, len(emoji.Emojis))
|
emojis = make(map[string]string, len(emoji.Emojis))
|
||||||
|
if !emoji.NoDefault {
|
||||||
for _, item := range emoji.Emojis {
|
for _, item := range emoji.Emojis {
|
||||||
for ikey, ival := range item {
|
for ikey, ival := range item {
|
||||||
emojis[ikey] = ival
|
emojis[ikey] = ival
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emoji = emojiHolder{}
|
emoji = emojiHolder{}
|
||||||
err = unmarshalJsonFileIgnore404("./config/emoji.json", &emoji)
|
err = unmarshalJsonFileIgnore404("./config/emoji.json", &emoji)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if emoji.NoDefault {
|
||||||
|
emojis = make(map[string]string)
|
||||||
|
}
|
||||||
|
|
||||||
for _, item := range emoji.Emojis {
|
for _, item := range emoji.Emojis {
|
||||||
for ikey, ival := range item {
|
for ikey, ival := range item {
|
||||||
|
@ -1098,7 +1104,7 @@ func parseMediaString(data string, settings *ParseSettings) (media MediaEmbed, o
|
||||||
}
|
}
|
||||||
ytInvalid2 := func(t string) bool {
|
ytInvalid2 := func(t string) bool {
|
||||||
for _, ch := range t {
|
for _, ch := range t {
|
||||||
if !((ch > 47 && ch < 58) || ch == 'h' || ch =='m' || ch =='s') {
|
if !((ch > 47 && ch < 58) || ch == 'h' || ch == 'm' || ch == 's') {
|
||||||
//fmt.Printf("ytInvalid2 true: %+v\n",t)
|
//fmt.Printf("ytInvalid2 true: %+v\n",t)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -1112,34 +1118,34 @@ func parseMediaString(data string, settings *ParseSettings) (media MediaEmbed, o
|
||||||
if ytInvalid(v) {
|
if ytInvalid(v) {
|
||||||
return media, true
|
return media, true
|
||||||
}
|
}
|
||||||
var t,t2 string
|
var t, t2 string
|
||||||
tt, ok := query["t"]
|
tt, ok := query["t"]
|
||||||
if ok && len(tt) >= 1 {
|
if ok && len(tt) >= 1 {
|
||||||
t, t2 = tt[0], tt[0]
|
t, t2 = tt[0], tt[0]
|
||||||
}
|
}
|
||||||
media.Type = ERawExternal
|
media.Type = ERawExternal
|
||||||
if t != "" && !ytInvalid2(t) {
|
if t != "" && !ytInvalid2(t) {
|
||||||
s,m,h := parseDuration(t2)
|
s, m, h := parseDuration(t2)
|
||||||
calc := s + (m * 60) + (h * 60 * 60)
|
calc := s + (m * 60) + (h * 60 * 60)
|
||||||
if calc > 0 {
|
if calc > 0 {
|
||||||
t = "&t="+t
|
t = "&t=" + t
|
||||||
t2 = "?start="+strconv.Itoa(calc)
|
t2 = "?start=" + strconv.Itoa(calc)
|
||||||
} else {
|
} else {
|
||||||
t, t2 = "",""
|
t, t2 = "", ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
l := "https://"+ host + path+"?v="+v+t
|
l := "https://" + host + path + "?v=" + v + t
|
||||||
media.Body = "<iframe class='postIframe'src='https://www.youtube-nocookie.com/embed/" + v+t2 + "'frameborder=0 allowfullscreen></iframe><noscript><a href='" + l+"'>"+l+"</a></noscript>"
|
media.Body = "<iframe class='postIframe'src='https://www.youtube-nocookie.com/embed/" + v + t2 + "'frameborder=0 allowfullscreen></iframe><noscript><a href='" + l + "'>" + l + "</a></noscript>"
|
||||||
return media, true
|
return media, true
|
||||||
}
|
}
|
||||||
} else if host == "youtu.be" {
|
} else if host == "youtu.be" {
|
||||||
v := strings.TrimPrefix(path,"/")
|
v := strings.TrimPrefix(path, "/")
|
||||||
if ytInvalid(v) {
|
if ytInvalid(v) {
|
||||||
return media, true
|
return media, true
|
||||||
}
|
}
|
||||||
l := "https://youtu.be/"+v
|
l := "https://youtu.be/" + v
|
||||||
media.Type = ERawExternal
|
media.Type = ERawExternal
|
||||||
media.Body = "<iframe class='postIframe'src='https://www.youtube-nocookie.com/embed/" + v + "'frameborder=0 allowfullscreen></iframe><noscript><a href='" + l+"'>"+l+"</a></noscript>"
|
media.Body = "<iframe class='postIframe'src='https://www.youtube-nocookie.com/embed/" + v + "'frameborder=0 allowfullscreen></iframe><noscript><a href='" + l + "'>" + l + "</a></noscript>"
|
||||||
return media, true
|
return media, true
|
||||||
} else if strings.HasPrefix(host, "www.nicovideo.jp") && strings.HasPrefix(path, "/watch/sm") {
|
} else if strings.HasPrefix(host, "www.nicovideo.jp") && strings.HasPrefix(path, "/watch/sm") {
|
||||||
vid, err := strconv.ParseInt(strings.TrimPrefix(path, "/watch/sm"), 10, 64)
|
vid, err := strconv.ParseInt(strings.TrimPrefix(path, "/watch/sm"), 10, 64)
|
||||||
|
@ -1150,8 +1156,8 @@ func parseMediaString(data string, settings *ParseSettings) (media MediaEmbed, o
|
||||||
}
|
}
|
||||||
media.Type = ERawExternal
|
media.Type = ERawExternal
|
||||||
sm := strconv.FormatInt(vid, 10)
|
sm := strconv.FormatInt(vid, 10)
|
||||||
l := "https://"+ host + sport + path
|
l := "https://" + host + sport + path
|
||||||
media.Body = "<iframe class='postIframe'src='https://embed.nicovideo.jp/watch/sm" + sm + "?jsapi=1&playerId=1'frameborder=0 allowfullscreen></iframe><noscript><a href='" + l+"'>"+l+"</a></noscript>"
|
media.Body = "<iframe class='postIframe'src='https://embed.nicovideo.jp/watch/sm" + sm + "?jsapi=1&playerId=1'frameborder=0 allowfullscreen></iframe><noscript><a href='" + l + "'>" + l + "</a></noscript>"
|
||||||
return media, true
|
return media, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1192,12 +1198,12 @@ func parseMediaString(data string, settings *ParseSettings) (media MediaEmbed, o
|
||||||
return media, true
|
return media, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDuration(dur string) (s,m,h int) {
|
func parseDuration(dur string) (s, m, h int) {
|
||||||
var ibuf []byte
|
var ibuf []byte
|
||||||
for _, ch := range dur {
|
for _, ch := range dur {
|
||||||
switch {
|
switch {
|
||||||
case ch > 47 && ch < 58:
|
case ch > 47 && ch < 58:
|
||||||
ibuf = append(ibuf,byte(ch))
|
ibuf = append(ibuf, byte(ch))
|
||||||
case ch == 'h':
|
case ch == 'h':
|
||||||
h, _ = strconv.Atoi(string(ibuf))
|
h, _ = strconv.Atoi(string(ibuf))
|
||||||
ibuf = ibuf[:0]
|
ibuf = ibuf[:0]
|
||||||
|
@ -1213,7 +1219,7 @@ func parseDuration(dur string) (s,m,h int) {
|
||||||
if h == 0 && m == 0 && s < 2 {
|
if h == 0 && m == 0 && s < 2 {
|
||||||
s = 0
|
s = 0
|
||||||
}
|
}
|
||||||
return s,m,h
|
return s, m, h
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Write a test for this
|
// TODO: Write a test for this
|
||||||
|
|
Loading…
Reference in New Issue