-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommands.sh
212 lines (145 loc) · 4.47 KB
/
commands.sh
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
#///// By iicc \\\\\
if [ "$1" = "source" ];then
# Place the TOKEN in token file.
TOKEN=$(cat token)
ADMINS='Place here the ID of the admins of the bot separated by commas'
ROOT='Put here the ID of the owner of the bot'
else
echo "--------------------------------------------------------------------------------------"
echo ""
echo $ADMINS | grep ${USER[ID]}
if [ $? == 0 ]; then
ADMIN=1
else
ADMIN=0
fi
# LOG BOT ON TERMINAL #
echo "MSG: $MESSAGE | USER: ${USER[USERNAME]} | ID: ${USER[ID]} | CHAT: ${CHAT[TITLE]} | ID: ${CHAT[ID]}"
echo ""
case $MESSAGE in
'/help')
if [ "$ADMIN" == "1" ]; then
send_action "${CHAT[ID]}" "typing"
send_markdown_message "${CHAT[ID]}" "*Comandos admins:*
/warn Da un aviso a la persona por reply.
/ban Banea por reply.
/clear Quita todos los avisos por reply.
/info Informacion de los avisos de ese user.
/warns Muestra la gente avisada."
else
send_markdown_message "${USER[ID]}" "*No eres admin*"
fi
;;
'/backup')
if [ "$ADMIN" == "1" ]; then
send_file "$ROOT" "bashbot.sh" "Warnbot TG API"
send_file "$ROOT" "commands.sh" "Warnbot code"
send_file "$ROOT" "count" "Stats"
send_file "$ROOT" "warns.txt" "Warns"
else
send_markdown_message "${CHAT[ID]}" "*No eres admin*"
fi
;;
'/warns')
if [ "$ADMIN" == "1" ]; then
### Not finished###
send_action "${CHAT[ID]}" "typing"
while read linea
do
ID=$(echo $linea | cut -d "_" -f1)
N=$(echo $linea | cut -d "_" -f2)
US=$(curl ....)
curl -s "https://api.pwrtelegram.xyz/botxxxxxxxxxxxxxxx/getChat" -d "chat_id=$ID"
if [ -z "${US}" ]; then
US=$(echo "Sin alias" )
fi
echo "$US tiene $N avisos" >> warns.tmp
done < warns.txt
SEND=$(cat warns.tmp)
send_markdown_message "${CHAT[ID]}" "$SEND"
rm warns.tmp
else
send_markdown_message "${USER[ID]}" "*No eres admin*"
fi
;;
'/id')
send_message "${CHAT[ID]}" "$REPLYID ."
;;
'/start')
echo $USERNAMECHAT ${USER[ID]} >> stats.txt
send_action "${USER[ID]}" "typing"
send_markdown_message "${USER[ID]}" "*Bienvenido, pero no eres admin...*"
;;
'')
;;
*)
esac
# Functions
# ADMIN COMMANDS #
if [ "$ADMIN" == "1" ]; then
if [ -z "${REPLYUSERNAME}" ]; then
user=$(echo ${REPLYFIRST_NAME} )
else
user=$(echo @${REPLYUSERNAME} )
fi
echo "$user" | grep "_"
if [ $? == 0 ]; then
user=$(echo ${REPLYFIRST_NAME} )
fi
if [[ $MESSAGE =~ ^[\/!][Ww][Aa][Rr][nN] ]]; then
MSG=$(echo $MESSAGE | cut -d " " -f2-)
if [ "${#MESSAGE}" -gt "8" ]; then
MSG=$(echo "*Razon:* $MSG")
else
MSG=""
fi
if [ -z "${REPLYID}" ]; then
exit
fi
echo "$ADMINS" | grep "${REPLYID}"
if [ $? == 0 ]; then
exit
fi
cat warns.txt | grep "${REPLYID}"
if [ $? == 0 ]; then
A0=$(cat warns.txt | grep ${REPLYID} | head -1 | cut -d '_' -f2)
grep -v ${REPLYID} warns.txt > warns.bak
mv warns.bak warns.txt
AD=$(echo "$A0 + 1" | bc)
if [ "$AD" == "4" ]; then
AD=3
fi
echo "${REPLYID}_${AD}" >> warns.txt
else
echo "${REPLYID}_1" >> warns.txt
AD=1
fi
if [ "$AD" == "3" ]; then
kick_chat_member "${CHAT[ID]}" "${REPLYID}"
send_markdown_message "${CHAT[ID]}" "El usuario $user *ha sido baneado por pasar de las 3 advertencias*.
$MSG"
else
send_markdown_message "${CHAT[ID]}" "El usuario $user *ha sido avisado*.
$MSG
_Advertencias totales:_ * $AD *
_Advertencias para ban:_ *3*"
fi
elif [[ $MESSAGE =~ ^\/[Cc][Ll][Ee][Aa][Rr] ]]; then
grep -v ${REPLY[ID]} warns.txt > warns.bak
mv warns.bak warns.txt
send_markdown_message "${CHAT[ID]}" "El usuario $user *ya no tiene avisos*."
elif [[ $MESSAGE =~ ^\/[Bb][Aa][nN]+$ ]]; then
kick_chat_member "${CHAT[ID]}" "${REPLYID}"
send_markdown_message "${CHAT[ID]}" "El usuario $user *ha sido baneado*."
elif [[ $MESSAGE =~ ^\/[Ii][nN][fF][Oo]+$ ]]; then
cat warns.txt | grep "${REPLYID}"
if [ $? == 0 ]; then
A0=$(cat warns.txt | grep ${REPLYID} | head -1 | cut -d '_' -f2)
else
A0='0'
fi
send_markdown_message "${CHAT[ID]}" "El usuario $user *tiene $A0 avisos*."
fi
fi
fi