Spaces:
Sleeping
Sleeping
File size: 10,879 Bytes
89a7a7a aef1161 89a7a7a aef1161 89a7a7a 7eeba00 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a 3d6e111 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a e950685 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 7eeba00 aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a 7eeba00 89a7a7a aef1161 89a7a7a 7eeba00 89a7a7a 7eeba00 89a7a7a aef1161 89a7a7a 7eeba00 89a7a7a aef1161 89a7a7a aef1161 89a7a7a 9c7de01 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 89a7a7a aef1161 9c7de01 aef1161 89a7a7a 9c7de01 89a7a7a aef1161 89a7a7a aef1161 89a7a7a e950685 |
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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
from datetime import date, datetime, time
from random import choice
from traceback import format_exc
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from pyrogram import filters
from pyrogram.enums import ChatMemberStatus, ChatType
from pyrogram.types import CallbackQuery
from pyrogram.types import InlineKeyboardButton as IKB
from pyrogram.types import InlineKeyboardMarkup as IKM
from pyrogram.types import Message
from Powers import BDB_URI, LOGGER, TIME_ZONE
from Powers.bot_class import Gojo
from Powers.database.chats_db import Chats
if BDB_URI:
from Powers.plugins import bday_cinfo, bday_info
from Powers.utils.custom_filters import command
from Powers.utils.extras import birthday_wish
def give_date(date,form = "%d/%m/%Y"):
datee = datetime.strptime(date,form).date()
return datee
@Gojo.on_message(command("remember"))
async def remember_me(c: Gojo, m: Message):
if not BDB_URI:
await m.reply_text("BDB_URI is not configured")
return
splited = m.text.split()
if len(splited) == 1:
await m.reply_text("**USAGE**:\n/remember [username or user id or reply to user] [DOB]\nDOB should be in format of dd/mm/yyyy\nYear is optional it is not necessary to pass it")
return
if len(splited) != 2 and m.reply_to_message:
await m.reply_text("**USAGE**:\n/remember [username or user id or reply to user] [DOB]\nDOB should be in format of dd/mm/yyyy\nYear is optional it is not necessary to pass it")
return
DOB = splited[1] if len(splited) == 2 else splited[2]
if len(splited) == 2 and m.reply_to_message:
user = m.reply_to_message.from_user.id
elif not m.reply_to_message:
user = m.from_user.id
else:
try:
u_id = int(splited[1])
except ValueError:
pass
try:
user = await c.get_users(u_id)
except Exception:
u_u = await c.resolve_peer(u_id)
try:
user = (await c.get_users(u_u.user_id)).id
except KeyError:
await m.reply_text("Unable to find the user")
return
DOB = DOB.split("/")
if len(DOB) != 3 and len(DOB) != 2:
await m.reply_text("DOB should be in format of dd/mm/yyyy\nYear is optional it is not necessary to pass it")
return
is_correct = False
if len(DOB) == 3:
is_correct = (len(DOB[2]) == 4)
if len(DOB[0]) != 2 and len(DOB[1]) !=2 and not is_correct:
await m.reply_text("DOB should be in format of dd/mm/yyyy\nYear is optional it is not necessary to pass it")
return
try:
date = int(DOB[0])
month = int(DOB[1])
if is_correct:
year = int(DOB[2])
is_year = 1
else:
year = "1900"
is_year = 0
DOB = f"{str(date)}/{str(month)}/{str(year)}"
except ValueError:
await m.reply_text("DOB should be numbers only")
return
data = {"user_id":user,"dob":DOB,"is_year":is_year}
try:
result = bday_info.find_one({"user_id":user})
if result:
await m.reply_text("User is already in my database")
return
except Exception as e:
await m.reply_text(f"Got an error\n{e}")
LOGGER.error(e)
LOGGER.error(format_exc())
return
try:
bday_info.insert_one(data)
await m.reply_text("Your birthday is now registered in my database")
except Exception as e:
await m.reply_text(f"Got an error\n{e}")
LOGGER.error(e)
LOGGER.error(format_exc())
return
@Gojo.on_message(command(["removebday","rmbday"]))
async def who_are_you_again(c: Gojo, m: Message):
if not BDB_URI:
await m.reply_text("BDB_URI is not configured")
return
user = m.from_user.id
try:
result = bday_info.find_one({"user_id":user})
if not result:
await m.reply_text("User is not in my database")
return
elif result:
bday_info.delete_one({"user_id":user})
await m.reply_text("Removed your birthday")
return
except Exception as e:
await m.reply_text(f"Got an error\n{e}")
return
@Gojo.on_message(command(["nextbdays","nbdays","birthdays","bdays"]))
async def who_is_next(c: Gojo, m: Message):
if not BDB_URI:
await m.reply_text("BDB_URI is not configured")
return
blist = list(bday_info.find())
if m.chat.type == ChatType.PRIVATE:
await m.reply_text("Use it in group")
return
curr = datetime.now(TIME_ZONE).date()
xx = await m.reply_text("📆")
users = []
if blist:
for i in blist:
if Chats(m.chat.id).user_is_in_chat(i["user_id"]):
dob = give_date(i["dob"])
if dob.month >= curr.month:
if (dob.month == curr.month and not dob.day < curr.day) or dob.month >= curr.month:
users.append(i)
elif dob.month < curr.month:
pass
if len(users) == 10:
break
if not users:
await xx.delete()
await m.reply_text("No birthdays found :/")
return
txt = "🎊 Upcomming Birthdays Are 🎊\n"
for i in users:
DOB = give_date(i["dob"])
dete = date(curr.year, DOB.month, DOB.day)
leff = (dete - curr).days
txt += f"`{i['user_id']}` : {leff} days left"
txt += "\n\nYou can use /info [user id] to get info about the user"
await xx.delete()
await m.reply_text(txt)
return
@Gojo.on_message(command(["getbday","gbday","mybirthday","mybday"]))
async def cant_recall_it(c: Gojo, m: Message):
if not BDB_URI:
await m.reply_text("BDB_URI is not configured")
return
user = m.from_user.id
men = m.from_user.mention
if m.reply_to_message:
user = m.reply_to_message.from_user.id
men = m.reply_to_message.from_user.mention
try:
result = bday_info.find_one({"user_id":user})
if not result:
await m.reply_text("User is not in my database")
return
except Exception as e:
await m.reply_text(f"Got an error\n{e}")
return
curr = datetime.now(TIME_ZONE).date()
u_dob = give_date(result["dob"])
if u_dob.month < curr.month:
next_b = date(curr.year + 1, u_dob.month, u_dob.day)
days_left = (next_b - curr).days
txt = f"{men} 's birthday is passed 🫤\nDays left until next one {days_left}"
else:
u_dobm = date(curr.year, u_dob.month, u_dob.day)
days_left = (u_dobm - curr).days
txt = f"User's birthday is coming🥳\nDays left : {days_left}"
await m.reply_text(txt)
return
@Gojo.on_message(command(["settingbday","sbday"]))
async def chat_birthday_settings(c: Gojo, m: Message):
if not BDB_URI:
await m.reply_text("BDB_URI is not configured")
return
if m.chat.type == ChatType.PRIVATE:
await m.reply_text("Use in groups")
return
chats = m.chat.id
c_in = bday_cinfo.find_one({"chat_id":chats})
kb = IKM(
[
[
IKB(f"{'Yes' if not c_in else 'No'}",f"switchh_{'yes' if not c_in else 'no'}"),
IKB("Close", "f_close")
]
]
)
await m.reply_text("Do you want to wish members for their birthday in the group?",reply_markup=kb)
return
@Gojo.on_callback_query(filters.regex("^switchh_"))
async def switch_on_off(c:Gojo, q: CallbackQuery):
user = (await q.message.chat.get_member(q.from_user.id)).status
await q.message.chat.get_member(q.from_user.id)
if user not in [ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER]:
await q.answer("...")
return
data = q.data.split("_")[1]
chats = q.message.chat.id
xXx = {"chat_id":chats}
if data == "yes":
bday_cinfo.delete_one(xXx)
elif data == "no":
bday_cinfo.insert_one(xXx)
await q.edit_message_text(f"Done! I will {'wish' if data == 'yes' else 'not wish'}",reply_markup=IKM([[IKB("Close", "f_close")]]))
return
scheduler = AsyncIOScheduler()
scheduler.timezone = TIME_ZONE
scheduler_time = time(0,0,0)
async def send_wishish(JJK: Gojo):
c_list = Chats.list_chats_by_id()
blist = list(bday_info.find())
curr = datetime.now(TIME_ZONE).date()
cclist = list(bday_cinfo.find())
for i in blist:
dob = give_date(i["dob"])
if dob.month == curr.month and dob.day == curr.day:
for j in c_list:
if cclist and (j in cclist):
return
try:
agee = ""
if i["is_year"]:
agee = curr.year - dob.year
if str(agee).endswith("1"):
agee = f"{agee}st"
elif str(agee).endswith("2"):
agee = f"{agee}nd"
elif str(agee).endswith("3"):
agee = f"{agee}rd"
else:
agee = f"{agee}th"
U = await JJK.get_chat_member(chat_id=j,user_id=i["user_id"])
wish = choice(birthday_wish)
if U.status in [ChatMemberStatus.MEMBER,ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER]:
xXx = await JJK.send_message(j,f"Happy {agee} birthday {U.user.mention}🥳\n{wish}")
try:
await xXx.pin()
except Exception:
pass
except Exception:
pass
""""
from datetime import date, datetime
#form =
num = "18/05/2005"
st = "18 May 2005"
timm = datetime.strptime(num,"%d/%m/%Y").date()
x = datetime.now().date()
if timm.month < x.month:
next_b = date(x.year + 1, timm.month, timm.day)
days_left = (next_b - x).days
else:
timmm = date(x.year, timm.month, timm.day)
days_left = (timmm - x).days
print(days_left)
print(x.year - timm.year)
"""
__PLUGIN__ = "birthday"
__HELP__ = """
• /remember [reply to user] [DOB] : To registers user date of birth in my database. If not replied to user then the DOB givien will be treated as yours
• /nextbdays (/nbdays,/brithdays,/bdays) : Return upcoming birthdays of 10 users
• /removebday (/rmbday) : To remove birthday from database (One can only remove their data from database not of others)
• /settingbday (/sbday) : To configure the settings for wishing and all for the chat
• /getbday (/gbday,/mybirthday,/mybday) [reply to user] : If replied to user get the replied user's birthday else returns your birthday
DOB should be in format of dd/mm/yyyy
Year is optional it is not necessary to pass it
"""
|