Captain Ezio commited on
Commit
51c8b2f
·
1 Parent(s): 35ff700

Update complete `v 2.1.0`

Browse files
Powers/database/giveaway_db.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from threading import RLock
2
+ from traceback import format_exc
3
+
4
+ from Powers import LOGGER
5
+ from Powers.database import MongoDB
6
+ from Powers.utils.msg_types import Types
7
+
8
+ INSERTION_LOCK = RLock()
9
+
10
+ class GIVEAWAY(MongoDB):
11
+ """Class to store giveaway info of the chat"""
12
+ db_name = "giveaway"
13
+
14
+ def __init__(self):
15
+ super().__init__(self.db_name)
16
+
17
+ def save_give(
18
+ self,
19
+ chat_id:int, # Chat id for in which user want to do giveaway
20
+ group_id:int, # entries chat id
21
+ user_id: int, # User id of the person who have started the giveaway
22
+ is_new:int=0, # Can old user vote? 0 for yes 1 for no
23
+ entries:int=1, # Entries are allowed? 0 for no 1 for yes
24
+ give:int = 1, # Giveaway is on or not? 1 for on 0 for off
25
+ force_c:bool = False # Force change the info
26
+ ):
27
+ with INSERTION_LOCK:
28
+ curr = self.find_one({"chat_id":chat_id})
29
+ if curr:
30
+ return False
31
+ else:
32
+ curr = self.find_one({"where":group_id})
33
+ if curr and not force_c:
34
+ return False
35
+ else:
36
+ self.delete_one({"chat_id":chat_id,"where":group_id,"user_id":user_id,})
37
+ self.insert_one(
38
+ {
39
+ "chat_id":chat_id,
40
+ "where":group_id,
41
+ "user_id":user_id,
42
+ "is_new":is_new,
43
+ "entries":entries,
44
+ "is_give":give
45
+ }
46
+ )
47
+ return True
48
+
49
+ def give_info(self,group_id = 0, u_id = 0):
50
+ with INSERTION_LOCK:
51
+ if u_id and group_id:
52
+ curr = self.find_one({"where":group_id, "user_id":u_id})
53
+ if curr:
54
+ return curr
55
+ else:
56
+ curr = self.find_one({"chat_id":group_id, "user_id":u_id})
57
+ if curr:
58
+ return curr
59
+ else:
60
+ return False
61
+ elif u_id:
62
+ curr = self.find_one({"user_id":u_id})
63
+ if curr:
64
+ return curr
65
+ elif group_id:
66
+ curr = self.find_one({"where":group_id})
67
+ if curr:
68
+ return curr
69
+ else:
70
+ curr = self.find_one({"chat_id":group_id})
71
+ if curr:
72
+ return curr
73
+ else:
74
+ return False
75
+
76
+ def is_vote(self, group_id):
77
+ with INSERTION_LOCK:
78
+ curr = self.find_one({"where": group_id})
79
+ if curr:
80
+ return True
81
+ return False
82
+
83
+ def start_vote(self,chat_id):
84
+ with INSERTION_LOCK:
85
+ curr = self.find_one({"chat_id":chat_id})
86
+ if curr:
87
+ self.update({"chat_id":chat_id},{"is_give":1})
88
+ return True
89
+ return False
90
+
91
+ def stop_entries(self,chat_id):
92
+ with INSERTION_LOCK:
93
+ curr = self.find_one({"chat_id":chat_id})
94
+ if curr:
95
+ self.update({"chat_id":chat_id},{"entries":0})
96
+ return True
97
+ return False
98
+
99
+ def update_is_old(self,chat_id,old):
100
+ with INSERTION_LOCK:
101
+ curr = self.find_one({"chat_id":chat_id})
102
+ if curr:
103
+ self.update({"chat_id":chat_id},{"is_new":old})
104
+ return True
105
+ return False
106
+
107
+ def stop_give(self, chat_id):
108
+ with INSERTION_LOCK:
109
+ curr = self.find_one({"chat_id":chat_id})
110
+ if curr:
111
+ self.update({"chat_id":chat_id},{"is_give":0})
112
+ return True
113
+ return True
Powers/plugins/giveaway.py ADDED
@@ -0,0 +1,456 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from datetime import datetime, timedelta
3
+ from traceback import format_exc
4
+
5
+ from pyrogram import filters
6
+ from pyrogram.enums import ChatMemberStatus as CMS
7
+ from pyrogram.enums import ChatType as CT
8
+ from pyrogram.enums import MessageMediaType as MMT
9
+ from pyrogram.errors import UserNotParticipant
10
+ from pyrogram.types import CallbackQuery
11
+ from pyrogram.types import InlineKeyboardButton as IKB
12
+ from pyrogram.types import InlineKeyboardMarkup as IKM
13
+ from pyrogram.types import Message
14
+
15
+ from Powers import LOGGER
16
+ from Powers.bot_class import Gojo
17
+ from Powers.database.giveaway_db import GIVEAWAY
18
+ from Powers.utils.custom_filters import admin_filter, command
19
+ from Powers.vars import Config
20
+
21
+ user_entry = {} # {c_id : {participants_id : 0}}} dict be like
22
+ voted_user = {} # {c_id : [voter_ids]}} dict be like
23
+ total_entries = {} # {c_id : [user_id]} dict be like for participants
24
+ left_deduct = {} # {u_id:p_id} u_id = user who have voted, p_id = participant id. Will deduct vote from participants account if user leaves
25
+ rejoin_try = {} # store the id of the user who lefts the chat while giveaway under-process {c_id:[]}
26
+
27
+ async def start_give_one_help(c: Gojo, m: Message):
28
+ while True:
29
+ channel_id = await c.ask(text="Sende me id of the channel and make sure I am admin their. If you don't have id forward a post from your chat.\nType /cancel cancel the current process",chat_id = m.chat.id,filters=filters.text)
30
+ if channel_id.text:
31
+ if str(channel_id.text).lower() == "/cancel":
32
+
33
+ await c.send_message(m.from_user.id, "Cancelled")
34
+ return None, None, None, None, None
35
+ try:
36
+ c_id = int(channel_id.text)
37
+ try:
38
+ um = await c.send_message(c_id, "Test")
39
+ await um.pin()
40
+ await um.unpin()
41
+ await um.delete()
42
+ c_id = c_id
43
+ break
44
+ except Exception:
45
+ await c.send_message(m.chat.id,f"Looks like I don't have admin privileges in the chat {c_id}")
46
+
47
+ except ValueError:
48
+ await c.send_message(m.chat.id,"Channel id should be integer type")
49
+
50
+ else:
51
+ if channel_id.forward_from_chat:
52
+ try:
53
+ c_id = channel_id.forward_from_chat.id
54
+ um = await c.send_message(c_id, "Test")
55
+ await um.pin()
56
+ await um.unpin()
57
+ await um.delete()
58
+ c_id = c_id
59
+ break
60
+ except Exception:
61
+ await c.send_message(m.chat.id,f"Looks like I don't have admin privileges in the chat {c_id}")
62
+
63
+ else:
64
+ await c.send_message(m.chat.id,f"Forward me content from chat where you want to start giveaway")
65
+ f_c_id = c_id
66
+ await c.send_message(m.chat.id,"Channel id received")
67
+ while True:
68
+ chat_id = await c.ask(text="Sende me id of the chat and make sure I am admin their. If you don't have id go in the chat and type /id.\nType /cancel to cancel the current process",chat_id = m.chat.id,filters=filters.text)
69
+ if chat_id.text:
70
+ if str(chat_id.text).lower() == "/cancel":
71
+ await c.send_message(m.from_user.id, "Cancelled")
72
+ return None, None, None, None, None
73
+ try:
74
+ cc_id = int(chat_id.text)
75
+ try:
76
+ cc_id = (await c.get_chat(cc_id)).id
77
+ s_c_id = cc_id
78
+ break
79
+ except Exception:
80
+ try:
81
+ cc_id = await c.resolve_peer(cc_id)
82
+ cc_id = (await c.get_chat(cc_id.channel_id)).id
83
+ s_c_id = cc_id
84
+ break
85
+ except Exception as e:
86
+ await c.send_message(m.chat.id,f"Looks like chat doesn't exist{e}")
87
+ except ValueError:
88
+ await c.send_message(m.chat.id,"Chat id should be integer type")
89
+
90
+ await c.send_message(m.chat.id,"Chat id received")
91
+
92
+ link = await c.export_chat_invite_link(cc_id)
93
+
94
+ yes_no = await c.ask(text="Do you want to allow old member of the channel can vote in this giveaway.\n**Yes: To allow**\n**No: To don't allow**\nNote that old mean user who is present in the chat for more than 48 hours",chat_id = m.from_user.id,filters=filters.text)
95
+ if yes_no.text.lower() == "yes":
96
+ is_old = 0
97
+ elif yes_no.text.lower() == "no":
98
+ is_old = 1
99
+ return f_c_id, s_c_id, m.from_user.id, is_old, link
100
+
101
+ @Gojo.on_message(command("startgiveaway"))
102
+ async def start_give_one(c: Gojo, m: Message):
103
+ try:
104
+ if m.chat.type != CT.PRIVATE:
105
+ await m.reply_text("**USAGE**\n/startgiveaway\nMeant to be used in private")
106
+ return
107
+ GA = GIVEAWAY()
108
+ g_id = await c.ask(text="Send me number of giveaway", chat_id = m.chat.id, filters=filters.text)
109
+ give_id = g_id.text.markdown
110
+ curr = GA.give_info(u_id=m.from_user.id)
111
+ if curr:
112
+ gc_id = curr["chat_id"]
113
+ c_id = curr["where"]
114
+ if curr["is_give"]:
115
+ await m.reply_text("One giveaway is already in progress")
116
+ return
117
+ con = await c.ask(text="You info is already present in my database do you want to continue\nYes : To start the giveaway with previous configurations\nNo: To create one",chat_id = m.chat.id,filters=filters.text)
118
+ await c.send_message(m.chat.id,"Done")
119
+ if con.text.lower == "yes":
120
+ yes_no = await c.ask(text="Ok.\nDo you want to allow old member of the channel can vote in this giveaway.\n**Yes: To allow**\n**No: To don't allow**\nNote that old mean user who is present in the chat for more than 48 hours",chat_id = m.from_user.id,filters=filters.text)
121
+ await c.send_message(m.chat.id,"Done")
122
+ if yes_no.text.lower() == "yes":
123
+ is_old = 0
124
+ elif yes_no.text.lower() == "no":
125
+ is_old = 1
126
+ f_c_id = c_id
127
+ s_c_id = gc_id
128
+ is_old = is_old
129
+ GA.update_is_old(c_id, is_old)
130
+ link = await c.export_chat_invite_link(s_c_id)
131
+ else:
132
+ f_c_id, s_c_id, m.from_user.id, is_old, link = await start_give_one_help(c, m)
133
+ if not f_c_id:
134
+ return
135
+ user_s1 = (await c.get_chat_member(f_c_id,m.from_user.id)).status
136
+ user_s2 = (await c.get_chat_member(s_c_id,m.from_user.id)).status
137
+ if user_s1 not in [CMS.OWNER, CMS.ADMINISTRATOR] and user_s2 not in user_s1 not in [CMS.OWNER, CMS.ADMINISTRATOR]:
138
+ await m.reply_text("You have to be owner or admin in the chat of which you have provided id")
139
+ return
140
+ curr = GA.save_give(f_c_id, s_c_id, m.from_user.id, is_old, force_c=True)
141
+ except Exception as e:
142
+ LOGGER.error(e)
143
+ LOGGER.error(format_exc())
144
+ return
145
+
146
+ if not curr:
147
+ await m.reply_text("One giveaway is already in progress")
148
+ return
149
+ reply = m.reply_to_message
150
+ giveaway_text = f"""
151
+ #Giveaway {give_id} ⟩⟩
152
+ ➖➖➖➖➖➖➖➖➖➖➖➖➖➖
153
+ If you want {'this' if reply else "you custom made logo"} logo
154
+ How to participate:
155
+ • Start the bot by pressing on **Start the bot**
156
+ • [Join the chat]({link}) by presseing on **Join the chat** and type `/enter`
157
+ ➖➖➖➖➖➖➖➖➖➖➖➖➖➖
158
+ Status : Entries open
159
+ """
160
+
161
+ kb = IKM([[IKB("Join the chat", url=link)],[IKB("Start the bot", url=f"https://{Config.BOT_USERNAME}.t.me/")]])
162
+ try:
163
+ if reply and (reply.media in [MMT.VIDEO, MMT.PHOTO] or (reply.document.mime_type.split("/")[0]=="image")):
164
+ if reply.photo:
165
+ pin = await c.send_photo(f_c_id, reply.photo.file_id,giveaway_text, reply_markup=kb)
166
+ elif reply.video:
167
+ pin = await c.send_video(f_c_id, reply.video.file_id, giveaway_text, reply_markup=kb)
168
+ elif reply.document:
169
+ download = await reply.download()
170
+ pin = await c.send_photo(f_c_id, download, giveaway_text, reply_markup=kb)
171
+ os.remove(download)
172
+ else:
173
+ pin = await c.send_message(f_c_id,giveaway_text, reply_markup=kb, disable_web_page_preview=True)
174
+ except Exception as e:
175
+ LOGGER.error(e)
176
+ LOGGER.error(format_exc())
177
+ await m.reply_text(f"Failed to send message to channel due to\n{e}")
178
+ return
179
+ c_in = await c.get_chat(f_c_id)
180
+ name = c_in.title
181
+ await m.reply_text(f"Giveaway is started now in [{name}]({c_in.invite_link})\nHere is the post link {pin.link}")
182
+ await pin.pin()
183
+
184
+
185
+
186
+ @Gojo.on_message(command("stopentry"))
187
+ async def stop_give_entry(c:Gojo, m: Message):
188
+ GA = GIVEAWAY()
189
+ u_id = m.from_user.id
190
+ curr = GA.give_info(u_id=u_id)
191
+ if not curr:
192
+ await m.reply_text("No current giveaway with the given channel id and giveaway id registered")
193
+ return
194
+ user = curr["user_id"]
195
+ if u_id != user:
196
+ await m.reply_text("You are not the one who have started the giveaway")
197
+ return
198
+ c_id = curr["chat_id"]
199
+ GA.stop_entries(c_id)
200
+ txt = f"""
201
+ Giveaway is closed!
202
+ ➖➖➖➖➖➖➖➖➖➖➖➖➖➖
203
+ Total number of entries registered {len(total_entries[c_id])}
204
+ ➖➖➖➖➖➖➖➖➖➖➖➖➖➖
205
+ Status : Entries closed
206
+ """
207
+ await m.reply_text("Stopped the further entries")
208
+ x = await c.send_message(c_id, txt)
209
+ await x.pin()
210
+ return
211
+
212
+ @Gojo.on_message(command("stopgiveaway"))
213
+ async def stop_give_away(c:Gojo, m: Message):
214
+ GA = GIVEAWAY()
215
+ u_id = m.from_user.id
216
+
217
+ curr = GA.give_info(u_id=u_id)
218
+ if not curr:
219
+ await m.reply_text("No current giveaway with the given channel id and giveaway id registered")
220
+ return
221
+ user = curr["user_id"]
222
+ c_id = curr["chat_id"]
223
+ if u_id != user:
224
+ await m.reply_text("You are not the one who have started the giveaway")
225
+ return
226
+ try:
227
+ if not len(user_entry[c_id]):
228
+ await m.reply_text("No entries found")
229
+ GA.stop_give(c_id)
230
+ await m.reply_text("Stopped the giveaway")
231
+ return
232
+ except KeyError:
233
+ GA.stop_give(c_id)
234
+ await m.reply_text("Stopped the giveaway")
235
+ return
236
+ GA.stop_give(c_id)
237
+ GA.stop_entries(c_id)
238
+ await m.reply_text("Stopped the giveaway")
239
+ highest = max(user_entry[c_id], key=lambda k:user_entry[c_id][k])
240
+ high = user_entry[c_id][highest]
241
+ user_high = (await c.get_users(highest)).mention
242
+ txt = f"""
243
+ Giveaway is closed!
244
+ ➖➖➖➖➖➖➖➖➖➖➖➖➖➖
245
+ ≡ Total participants: {len(total_entries[c_id])}
246
+ ≡ Total number of votes: {len(voted_user[c_id])}
247
+
248
+ ≡ Winner 🏆 : {user_high}
249
+ ≡ Vote got 🗳 : `{high}` votes
250
+ ➖➖➖➖➖➖➖➖➖➖➖➖➖➖
251
+ Thanks for participating
252
+ """
253
+ x = await c.send_message(c_id, txt)
254
+ await x.pin()
255
+ try:
256
+ rejoin_try[c_id].clear()
257
+ voted_user[c_id].clear()
258
+ user_entry[c_id].clear()
259
+ left_deduct.clear()
260
+ await m.reply_text("Stopped giveaway")
261
+ except KeyError:
262
+ pass
263
+ return
264
+
265
+ @Gojo.on_message(command("startvote"))
266
+ async def start_the_vote(c: Gojo, m: Message):
267
+ GA = GIVEAWAY()
268
+ u_id = m.from_user.id
269
+ curr = GA.give_info(u_id)
270
+ c_id = curr["chat_id"]
271
+ if not curr:
272
+ await m.reply_text("No current giveaway with the given channel id and giveaway id registered")
273
+ return
274
+ user = curr["user_id"]
275
+ if u_id != user:
276
+ await m.reply_text("You are not the one who have started the giveaway")
277
+ return
278
+ if not len(total_entries[c_id]):
279
+ await m.reply_text("No entires found")
280
+ return
281
+ users = await c.get_users(total_entries[c_id])
282
+ for user in users:
283
+ u_id = user.id
284
+ full_name = user.first_name
285
+ if user.last_name and user.first_name:
286
+ full_name = user.first_name +" "+ user.last_name
287
+ u_name = user.username if user.username else user.mention
288
+ txt = f"""
289
+ Participant's info:
290
+
291
+ ≡ Participant's ID : `{u_id}`
292
+ ≡ Participant's name : {full_name}
293
+ ≡ Participant's {'username' if user.username else "mention"} : {'@'if user.username else ""}{u_name}
294
+ """
295
+ if not len(user_entry):
296
+ user_entry[c_id] = {u_id:0}
297
+ else:
298
+ try:
299
+ user_entry[c_id][u_id] = 0
300
+ except KeyError:
301
+ user_entry[c_id] = {u_id:0}
302
+ vote_kb = IKM([[IKB("❤️", f"vote_{c_id}_{u_id}_0")]])
303
+ um = await c.send_message(c_id, txt, reply_markup=vote_kb)
304
+ c_link = um.chat.username
305
+ if not c_link:
306
+ c_link = um.chat.invite_link
307
+ txt_ib = f"Voting is now started\nHere is your vote message link {um.link}.\nHere is chat's {'join link' if not um.chat.username else 'username'} {'@' if um.chat.username else ''}{c_link}\n\n**Thing to keep in mind**\nIf user lefts the chat after voting your vote count will be deducted.\nIf an user left and rejoins the chat he will not be able to vote.\nIf an user is not part of the chat then he'll not be able to vote"
308
+ await c.send_message(u_id, txt_ib, disable_web_page_preview=True)
309
+ await m.reply_text("Started the voting")
310
+ return
311
+
312
+ @Gojo.on_message(command("enter"))
313
+ async def register_user(c: Gojo, m: Message):
314
+ GA = GIVEAWAY()
315
+ curr = GA.is_vote(m.chat.id)
316
+ if not curr:
317
+ await m.reply_text("No giveaway to participate in.\nOr may be entries are closed now")
318
+ return
319
+ curr = GA.give_info(m.chat.id)
320
+ c_id = curr["chat_id"]
321
+ if len(total_entries):
322
+ try:
323
+ if m.from_user.id in total_entries[c_id]:
324
+ await m.reply_text("You are already registered")
325
+ return
326
+ except KeyError:
327
+ pass
328
+ try:
329
+ await c.send_message(m.from_user.id, "Thanks for participating in the giveaway")
330
+ except Exception:
331
+ await m.reply_text("Start the bot first\nAnd try again",reply_markup=IKM([[IKB("Star the bot", url=f"https://{Config.BOT_USERNAME}.t.me/")]]))
332
+ return
333
+ curr = GA.give_info(m.chat.id)
334
+ c_id = curr["chat_id"]
335
+ if not len(total_entries):
336
+ total_entries[c_id] = [m.from_user.id]
337
+ else:
338
+ try:
339
+ if m.from_user.id not in total_entries[c_id]:
340
+ total_entries[c_id].append(m.from_user.id)
341
+ else:
342
+ pass
343
+ except KeyError:
344
+ total_entries[c_id] = [m.from_user.id]
345
+ await m.reply_text("You are registered successfully\n**Don't block the bot because you are going to get info about giveaway via bot**")
346
+ return
347
+
348
+ @Gojo.on_callback_query(filters.regex("^vote_"))
349
+ async def vote_increment(c: Gojo, q: CallbackQuery):
350
+ GA = GIVEAWAY()
351
+ data = q.data.split("_")
352
+ c_id = int(data[1])
353
+ u_id = int(data[2])
354
+ votes = int(data[3])
355
+ curr = GA.give_info(c_id)
356
+ if not curr:
357
+ return
358
+ if len(rejoin_try):
359
+ try:
360
+ if q.from_user.id in rejoin_try[c_id]:
361
+ await q.answer("You can't vote. Because your rejoined the chat during giveaway")
362
+ return
363
+ except KeyError:
364
+ pass
365
+ is_old = curr["is_new"]
366
+ can_old = False
367
+ if is_old:
368
+ can_old = datetime.now() - timedelta(days=2)
369
+ try:
370
+ is_part = await c.get_chat_member(c_id,q.from_user.id)
371
+ except UserNotParticipant:
372
+ await q.answer("Join the channel to vote", True)
373
+ return
374
+ if is_part.status not in [CMS.MEMBER, CMS.OWNER, CMS.ADMINISTRATOR]:
375
+ await q.answer("Join the channel to vote", True)
376
+ return
377
+ if can_old and can_old < is_part.joined_date:
378
+ await q.answer("Old member can't vote", True)
379
+ return
380
+ if not len(voted_user):
381
+ voted_user[c_id] = [q.from_user.id]
382
+ elif len(voted_user):
383
+ try:
384
+ if q.from_user.id in voted_user[c_id]:
385
+ await q.answer("You have already voted once", True)
386
+ return
387
+ voted_user[c_id].append(q.from_user.id)
388
+ except KeyError:
389
+ voted_user[c_id] = [q.from_user.id]
390
+ left_deduct[q.from_user.id] = u_id
391
+ try:
392
+ user_entry[c_id][u_id] += 1
393
+ new_vote = IKM([[IKB(f"❤️ {votes+1}", f"vote_{c_id}_{u_id}_{votes+1}")]])
394
+ await q.answer("Voted.")
395
+ await q.edit_message_reply_markup(new_vote)
396
+ except KeyError:
397
+ await q.answer("Voting has been closed for this giveaway",True)
398
+ return
399
+ except Exception as e:
400
+ LOGGER.error(e)
401
+ LOGGER.error(format_exc())
402
+
403
+ @Gojo.on_message(filters.left_chat_member)
404
+ async def rejoin_try_not(c:Gojo, m: Message):
405
+ user = m.left_chat_member
406
+ if not user:
407
+ return
408
+ GA = GIVEAWAY()
409
+ Ezio = GA.give_info(m.chat.id)
410
+ if not Ezio:
411
+ return
412
+ Captain = user.id
413
+ if len(voted_user):
414
+ if Captain in voted_user[m.chat.id]:
415
+ GB = int(left_deduct[Captain])
416
+ user_entry[m.chat.id][GB] -= 1
417
+ await c.send_message(GB,f"One user who have voted you left the chat so his vote is reduced from your total votes.\nNote that he will not able to vote if he rejoins the chat\nLeft user : {Captain}")
418
+ try:
419
+ rejoin_try[m.chat.id].append(Captain)
420
+ except KeyError:
421
+ rejoin_try[m.chat.id] = [Captain]
422
+ else:
423
+ try:
424
+ rejoin_try[m.chat.id].append(Captain)
425
+ except KeyError:
426
+ rejoin_try[m.chat.id] = [Captain]
427
+ return
428
+
429
+
430
+ __PLUGIN__ = "giveaway"
431
+
432
+ __alt_name__ = [
433
+ "giveaway",
434
+ "events"
435
+ ]
436
+
437
+ __HELP__ = """
438
+ **Giveaway**
439
+ • /enter : To participate in giveaway. Make sure the bot is started to get registered.
440
+
441
+ **Admin commands:**
442
+ • /startgiveaway : Start the giveaway. Reply to media to send giveaway start message with tagged media (Will only wrok in bot ib).
443
+ • /stopentry : Stop the further entries. Channel for which you want to stop the entries.
444
+ • /stopgiveaway : Stop the giveaway. Channel for which you want to stop the giveaway. Will also close voting at same time.
445
+ • /startvote : Start uploading all the user info and will start voting.
446
+
447
+ **All the above command (except `/startgiveaway`) can only be valid iff the user who started the giveaway gives them**
448
+
449
+ **USE ALL THE USER DEPENDENT COMMAND IN PRIVATE**
450
+
451
+ **Example:**
452
+ `/enter`
453
+
454
+ **NOTE**
455
+ Bot should be admin where you are doing giveaway and where you are taking entries
456
+ """
Version/version 2.1.0.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # V 2.0.0
2
+ ### Changes made:
3
+ - Added giveaway support in the bot. Which will help the user who do giveaways
4
+ - Now Dev users can't promote themselves neither they can restrict members
5
+ - Added **2 owner commands** `/restart` and `/update`
6
+ - Now bot can fetch user info and chat info on large scale. Minimized the chances to get user not found message
7
+ - Added **4 new lock types**
8
+ - Now using `/id <username of user>` will give the user's id as well.
9
+ - Improved stability.
10
+ - Fixed few bugs.
11
+ - Bug known 0
12
+ - Deployed and tested locally.
13
+
14
+ ## Report issues [here](https://github.com/Gojo-Bots/Gojo_Satoru/issues/new/choose) if find any.
15
+
16
+ ## Give ideas [here](https://github.com/Gojo-Bots/Gojo_Satoru/discussions/new?category=ideas) for next update.
17
+
18
+ ## Trying our best to give the best
19
+
20
+ ## Regards 🧑‍💻: [Captain Ezio](https://github.com/iamgojoof6eyes)