File size: 6,560 Bytes
cbb05ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import discord
from discord.ext import commands
from discord import app_commands
from datetime import datetime, timezone, timedelta

# Windows'ta tzdata eksik olabilir. Önce zoneinfo ile dene, yoksa pytz, yoksa UTC offset map'i
try:
    from zoneinfo import ZoneInfo
    _ZONEINFO_OK = True
except Exception:
    _ZONEINFO_OK = False

try:
    import pytz
    _PYTZ_OK = True
except Exception:
    _PYTZ_OK = False

CYBER_BLUE = discord.Color.from_rgb(52, 152, 219)
CYBER_GOLD = discord.Color.from_rgb(241, 196, 15)

# Yaygın şehirler ve timezone ID'leri
SEHIR_ZAMAN_DILIMI = {
    "istanbul": "Europe/Istanbul",
    "new york": "America/New_York",
    "los angeles": "America/Los_Angeles",
    "london": "Europe/London",
    "paris": "Europe/Paris",
    "berlin": "Europe/Berlin",
    "moscow": "Europe/Moscow",
    "dubai": "Asia/Dubai",
    "tokyo": "Asia/Tokyo",
    "seoul": "Asia/Seoul",
    "shanghai": "Asia/Shanghai",
    "singapore": "Asia/Singapore",
    "sydney": "Australia/Sydney",
    "mumbai": "Asia/Kolkata",
    "delhi": "Asia/Kolkata",
    "cairo": "Africa/Cairo",
    "toronto": "America/Toronto",
    "mexico city": "America/Mexico_City",
    "sao paulo": "America/Sao_Paulo",
    "amsterdam": "Europe/Amsterdam",
    "madrid": "Europe/Madrid",
    "rome": "Europe/Rome",
    "stockholm": "Europe/Stockholm",
    "utc": "UTC",
    "ankara": "Europe/Istanbul",
    "izmir": "Europe/Istanbul",
    "baku": "Asia/Baku",
    "riyadh": "Asia/Riyadh",
    "los santos": "America/Los_Angeles",
    "chicago": "America/Chicago",
    "denver": "America/Denver",
    "phoenix": "America/Phoenix",
    "hawaii": "Pacific/Honolulu",
    "auckland": "Pacific/Auckland",
    "johannesburg": "Africa/Johannesburg",
    "bangkok": "Asia/Bangkok",
    "jakarta": "Asia/Jakarta",
    "manila": "Asia/Manila",
    "hong kong": "Asia/Hong_Kong",
    "tel aviv": "Asia/Jerusalem",
    "kiev": "Europe/Kyiv",
    "kyiv": "Europe/Kyiv",
}

# UTC ofsetleri (saat cinsinden) — ZoneInfo/pytz yoksa yedek olarak
UTC_OFFSETS = {
    "istanbul": 3, "ankara": 3, "izmir": 3, "baku": 4,
    "london": 0, "paris": 1, "berlin": 1, "amsterdam": 1, "madrid": 1,
    "rome": 1, "stockholm": 1, "moscow": 3, "kyiv": 2, "kiev": 2,
    "dubai": 4, "riyadh": 3, "cairo": 2, "johannesburg": 2,
    "new york": -5, "toronto": -5, "chicago": -6, "mexico city": -6,
    "denver": -7, "phoenix": -7, "los angeles": -8,
    "sao paulo": -3,
    "mumbai": 5, "delhi": 5, "bangkok": 7, "jakarta": 7,
    "hong kong": 8, "shanghai": 8, "singapore": 8, "manila": 8,
    "tokyo": 9, "seoul": 9,
    "sydney": 11, "auckland": 13,
    "hawaii": -10,
    "tel aviv": 2,
    "utc": 0,
}


def _get_now_in_tz(tz_id: str, sehir_lower: str):
    """Verilen timezone ID'sine göre şimdiki zamanı döndürür. Yedek olarak UTC offset kullanır."""
    if _ZONEINFO_OK:
        try:
            tz = ZoneInfo(tz_id)
            return datetime.now(tz)
        except Exception:
            pass
    if _PYTZ_OK:
        try:
            tz = pytz.timezone(tz_id)
            return datetime.now(tz)
        except Exception:
            pass
    # Yedek: UTC ofseti ile
    offset = UTC_OFFSETS.get(sehir_lower, 0)
    return datetime.now(timezone.utc) + timedelta(hours=offset)


class TimeZoneCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command(name="saat", description="Belirli bir şehrin şu anki saatini gösterir.")
    async def saat(self, ctx: commands.Context, *, sehir: str):

        sehir_lower = sehir.lower().strip()
        tz_id = SEHIR_ZAMAN_DILIMI.get(sehir_lower)

        if not tz_id:
            # Yıldız eşleştirme: kısmi eşleşme
            for key, val in SEHIR_ZAMAN_DILIMI.items():
                if sehir_lower in key or key in sehir_lower:
                    tz_id = val
                    sehir_lower = key
                    break

        if not tz_id:
            await ctx.send(
                f"❌ `{sehir}` için zaman dilimi bulunamadı.\n"
                f"Örnek şehirler: `istanbul`, `london`, `tokyo`, `new york`, `dubai`, `moscow`, `sydney`, `los angeles`",
                ephemeral=True
            )
            return

        try:
            now = _get_now_in_tz(tz_id, sehir_lower)
            tarih_str = now.strftime("%d.%m.%Y")
            saat_str = now.strftime("%H:%M:%S")
            gun_str = ["Pzt", "Sal", "Çar", "Per", "Cum", "Cmt", "Paz"][now.weekday()]

            embed = discord.Embed(
                title=f"🕐 {sehir_lower.title()}",
                color=CYBER_GOLD,
                timestamp=datetime.now()
            )
            embed.add_field(name="🕒 Saat", value=f"**{saat_str}**", inline=True)
            embed.add_field(name="📅 Gün", value=f"**{gun_str}**", inline=True)
            embed.add_field(name="📆 Tarih", value=f"**{tarih_str}**", inline=True)
            embed.add_field(name="Zaman Dilimi", value=f"`{tz_id}`", inline=False)
            embed.set_footer(text="ArazAI Saat Sorgusu")
            await ctx.send(embed=embed)

        except Exception as e:
            await ctx.send(f"❌ Hata: {e}", ephemeral=True)

    @commands.command(name="saat-karşılaştır", description="Birden fazla şehrin şimdiki saatlerini karşılaştırır.")
    async def saat_karsilastir(self, ctx: commands.Context, *, sehirler: str):

        sehir_listesi = [s.strip() for s in sehirler.split("|") if s.strip()]
        if len(sehir_listesi) < 2:
            await ctx.send("❌ En az 2 şehir girin. (örn: istanbul | tokyo | london)", ephemeral=True)
            return

        embed = discord.Embed(title="🕐 Saat Karşılaştırma", color=CYBER_GOLD, timestamp=datetime.now())
        embed.set_footer(text="ArazAI Saat Sorgusu")

        for sehir in sehir_listesi[:10]:
            sehir_lower = sehir.lower()
            tz_id = SEHIR_ZAMAN_DILIMI.get(sehir_lower)
            if not tz_id:
                embed.add_field(name=f"❌ {sehir}", value="Bulunamadı", inline=True)
                continue
            try:
                now = _get_now_in_tz(tz_id, sehir_lower)
                saat_str = now.strftime("%H:%M")
                gun_str = ["Pzt", "Sal", "Çar", "Per", "Cum", "Cmt", "Paz"][now.weekday()]
                embed.add_field(name=f"📍 {sehir.title()}", value=f"**{saat_str}** ({gun_str})", inline=True)
            except:
                embed.add_field(name=f"❌ {sehir}", value="Hata", inline=True)

        await ctx.send(embed=embed)


async def setup(bot):
    await bot.add_cog(TimeZoneCog(bot))