-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathequal_func.go
162 lines (138 loc) · 3.32 KB
/
equal_func.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package telebot
import "reflect"
func (m *ForceReplyMarkup) deepEqual(other any) bool {
if m == nil {
return other == nil
}
otherMarkup, ok := other.(*ForceReplyMarkup)
if !ok {
return false
}
return m.ForceReply == otherMarkup.ForceReply &&
m.InputFieldPlaceholder == otherMarkup.InputFieldPlaceholder &&
m.Selective == otherMarkup.Selective
}
func (m *ReplyKeyboardRemove) deepEqual(other any) bool {
if m == nil {
return other == nil
}
otherMarkup, ok := other.(*ReplyKeyboardRemove)
if !ok {
return false
}
return m.RemoveKeyboard == otherMarkup.RemoveKeyboard &&
m.Selective == otherMarkup.Selective
}
func (m *InlineKeyboardMarkup) deepEqual(other any) bool {
if m == nil {
return other == nil
}
otherMarkup, ok := other.(*InlineKeyboardMarkup)
if !ok {
return false
}
if len(m.InlineKeyboard) != len(otherMarkup.InlineKeyboard) {
return false
}
for i, row := range m.InlineKeyboard {
if !row.deepEqual(otherMarkup.InlineKeyboard[i]) {
return false
}
}
return true
}
func (m *ReplyKeyboardMarkup) deepEqual(other any) bool {
if m == nil {
return other == nil
}
otherMarkup, ok := other.(*ReplyKeyboardMarkup)
if !ok {
return false
}
if len(m.Keyboard) != len(otherMarkup.Keyboard) {
return false
}
for i, row := range m.Keyboard {
if !row.deepEqual(otherMarkup.Keyboard[i]) {
return false
}
}
return m.IsPersistent == otherMarkup.IsPersistent &&
m.ResizeKeyboard == otherMarkup.ResizeKeyboard &&
m.OneTimeKeyboard == otherMarkup.OneTimeKeyboard &&
m.InputFieldPlaceholder == otherMarkup.InputFieldPlaceholder &&
m.Selective == otherMarkup.Selective
}
func (r *Row) deepEqual(other any) bool {
if r == nil {
return other == nil
}
otherRow, ok := other.(Row)
if !ok {
return false
}
if len(*r) != len(otherRow) {
return false
}
for i, button := range *r {
if !button.deepEqual(otherRow[i]) {
return false
}
}
return true
}
func (i *InlineKeyboardButton) deepEqual(other any) bool {
otherButton, ok := other.(*InlineKeyboardButton)
if !ok {
return false
}
return reflect.DeepEqual(i, otherButton)
}
func (i *KeyboardButton) deepEqual(other any) bool {
otherButton, ok := other.(*KeyboardButton)
if !ok {
return false
}
return reflect.DeepEqual(i, otherButton)
}
func (b *baseMarkUp) deepEqual(other any) bool {
if b == other {
return true
}
otherMarkup, ok := other.(*baseMarkUp)
if !ok {
inlineMarkup, ok := other.(*InlineKeyboardMarkup)
if ok {
return b.inline.deepEqual(inlineMarkup)
}
keyboardMarkup, ok := other.(*ReplyKeyboardMarkup)
if ok {
return b.keyboard.deepEqual(keyboardMarkup)
}
removeMarkup, ok := other.(*ReplyKeyboardRemove)
if ok {
return b.remove.deepEqual(removeMarkup)
}
forceReplyMarkup, ok := other.(*ForceReplyMarkup)
if ok {
return b.forceReply.deepEqual(forceReplyMarkup)
}
return false
}
if b.markupType != otherMarkup.markupType {
return false
}
switch b.markupType {
case markupTypeInline:
return b.inline.deepEqual(other.(*baseMarkUp).inline)
case markupTypeKeyboard:
return b.keyboard.deepEqual(other.(*baseMarkUp).keyboard)
case markupTypeRemoveKeyboard:
return b.remove.deepEqual(other.(*baseMarkUp).remove)
case markupTypeForceReply:
return b.forceReply.deepEqual(other.(*baseMarkUp).forceReply)
default:
panic("telebot: unknown markup type")
}
return false
}