-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrouter.go
161 lines (116 loc) · 4.81 KB
/
router.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
package main
// The router.go file is a file that "routes" a message received to the designed
// received (e.g. A normal text message should be "routed" to the text message "route"
// to be elaborated correctly)
func (ctx *Context) route() {
switch {
//Swtich the message based on its type
//Return message if there's no update
case ctx.Update == nil:
return
case ctx.Update.Message != nil:
//General message
message := ctx.Update.Message
switch {
case message.Text != "":
logMessage(0, "[", message.MessageID, "]", " Got text message from [", message.From.ID, "]")
textMessageRoute(ctx)
break
case message.Sticker != nil:
//Sticker
logMessage(0, "[", message.MessageID, "]", " Got sticker message from [", message.From.ID, "]")
break
case message.Photo != nil:
logMessage(0, "[", message.MessageID, "]", " Got photo from [", message.From.ID, "]")
//Photo
break
case message.Voice != nil:
logMessage(0, "[", message.MessageID, "]", " Got audio note from [", message.From.ID, "]")
//Voice audio file
break
case message.Document != nil:
//Document
logMessage(0, "[", message.MessageID, "]", " Got file from [", message.From.ID, "]")
break
case message.Location != nil:
logMessage(0, "[", message.MessageID, "]", " Got location from [", message.From.ID, "]")
break
case message.Contact != nil:
logMessage(0, "[", message.MessageID, "]", " Got contact from [", message.From.ID, "]")
break
case message.NewChatMembers != nil:
//New user(s)
for _, user := range *ctx.Update.Message.NewChatMembers {
logMessage(0, "[", message.MessageID, "]", " User joined (", user.UserName, ")[", message.From.ID, "]")
}
if ctx.Update.Message.GroupChatCreated {
logMessage(0, "[", message.MessageID, "]", " Group created")
} else {
userJoinedRoute(ctx)
}
//User joined
break
case message.VideoNote != nil:
//Video circolare
logMessage(0, "[", message.MessageID, "]", " Got video note from [", message.From.ID, "]")
break
case message.Video != nil:
logMessage(0, "[", message.MessageID, "]", " Got video from [", message.From.ID, "]")
break
case message.Venue != nil:
//NO IDEA <--- non capisco (Bhez)
logMessage(0, "[", message.MessageID, "]", " Got venue (to understand what this is) from [", message.From.ID, "]")
break
case message.LeftChatMember != nil:
//User removed (could be the bot)
logMessage(0, "[", message.MessageID, "]", " A user left or was kicked from the group [", message.From.ID, "]")
break
case message.PinnedMessage != nil:
logMessage(0, "[", message.MessageID, "]", " A message was pinned [", message.Chat.ID, "]")
break
case message.NewChatPhoto != nil:
logMessage(0, "[", message.MessageID, "]", " The chat photo was updated [", message.Chat.ID, "]")
break
case message.NewChatTitle != "":
logMessage(0, "[", message.MessageID, "]", " The chat title was updated [", message.Chat.ID, "]")
break
case message.MigrateToChatID != 0:
logMessage(0, "[", message.MessageID, "]", " The chat migrated to [", message.MigrateToChatID, "]")
break
}
case ctx.Update.EditedMessage != nil:
//Edited text message
logMessage(0, "[", ctx.Update.EditedMessage.MessageID, "]", " Got edit message from [", ctx.Update.EditedMessage.From.ID, "]")
editedTxtMessageRoute(ctx)
break
case ctx.Update.CallbackQuery != nil:
//Callback query
logMessage(0, "[", ctx.Update.CallbackQuery.ID, "]", " Got callback query from [", ctx.Update.CallbackQuery.From.ID, "]")
callbackQueryRoute(ctx)
break
case ctx.Update.InlineQuery != nil:
//Inline query
logMessage(0, "[", ctx.Update.InlineQuery.ID, "]", " Got inline query from [", ctx.Update.InlineQuery.From.ID, "]")
break
case ctx.Update.ChannelPost != nil:
//Channel post
logMessage(0, "[", ctx.Update.ChannelPost.MessageID, "]", " Got channel post from [", ctx.Update.ChannelPost.MessageID, "]")
break
case ctx.Update.EditedChannelPost != nil:
//Edited channel post
logMessage(0, "[", ctx.Update.EditedChannelPost.MessageID, "]", " Got edit of channel post from [", ctx.Update.EditedChannelPost.MessageID, "]")
break
case ctx.Update.PreCheckoutQuery != nil:
//Pre checkoput query - useless for now
logMessage(0, "[", ctx.Update.PreCheckoutQuery.ID, "]", " Got pre-checkout query from [", ctx.Update.PreCheckoutQuery.From.ID, "]")
break
case ctx.Update.ShippingQuery != nil:
//Pre shipping query
logMessage(0, "[", ctx.Update.ShippingQuery.ID, "]", " Got shipping query from [", ctx.Update.ShippingQuery.From.ID, "]")
break
case ctx.Update.ChosenInlineResult != nil:
//Chosen inline result -> Chosen inline element?
logMessage(0, "[", ctx.Update.ChosenInlineResult.InlineMessageID, "]", " Got chosen inline result from [", ctx.Update.ChosenInlineResult.From.ID, "]")
break
} //Message type swtich
}