test

swadhinbiswas committed 2 years ago
65bc70f
1 parent b84c4c7
commit 65bc70f
4 files changed
+82 -3
▼GithubfetchBot/main.py
+20-0
1
+from random import randint
1
2
from typing import Final
2
3
import os
3
4
import discord
6
7
load_dotenv()
7
8
TOKEN:Final[str] = os.getenv('DISCORD_TOKEN')
8
9
10
+intentes:discord.Intents=discord.Intents.default()
11
+intentes.messages=True
12
+intentes.reactions=True
13
+intentes.presences=True
14
+intentes.typing=True
15
+
16
+client:discord.Client=discord.Client(intents=intentes)
17
+
18
+
19
+
20
+def main()->None:
21
+ client.run(TOKEN)
22
+
23
+
24
+
25
+
26
+if __name__=="__main__":
27
+
28
+ main()
9
29
▼GithubfetchBot/responces.py
+14-3
1
+from random import choice, randint
2
+
1
3
def get_responce(user_input:str)->str:
2
- if user_input == "hi":
3
- return "Hello"
4
+ lower:str=user_input.lower()
5
+
6
+ if lower=="help":
7
+ return "This is a help message"
8
+ elif lower=="about":
9
+ return "This is a about message"
10
+ elif lower=="roll":
11
+ return str(randint(1,6))
12
+ elif lower=="":
13
+ return "Well you\'ve got to say something"
4
14
else:
5
- return "I don't understand that command"
15
+ return "I don't understand the command"
16
+
6
17
▼GithubfetchBot/sendwebhook.py
+31-0
1
+from discord import Webhook
2
+import os
3
+from dotenv import load_dotenv
4
+import aiohttp
5
+import time
6
+from typing import Final
7
+
8
+load_dotenv()
9
+WEBHOOK_URL:Final[str]=os.getenv('WEBHOOK_URL')
10
+
11
+
12
+from discord import Webhook
13
+import aiohttp
14
+
15
+async def foo():
16
+ async with aiohttp.ClientSession() as session:
17
+ webhook = Webhook.from_url(WEBHOOK_URL, session=session)
18
+ await webhook.send(messages, username='Foo')
19
+ time.sleep(3)
20
+
21
+ return await foo()
22
+
23
+
24
+async def main():
25
+ await foo()
26
+
27
+
28
+if __name__ == '__main__':
29
+ import asyncio
30
+ loop = asyncio.get_event_loop()
31
+ loop.run_until_complete(main())
0
32
▼GithubfetchBot/test.py
+17-0
1
+import os
2
+import discord
3
+import requests
4
+from typing import Final
5
+from dotenv import load_dotenv
6
+import pprint
7
+
8
+load_dotenv()
9
+API_KEY:Final[str]=os.getenv('API_KEY')
10
+cityname:Final[str]="Dhaka"
11
+url=f"https://api.openweathermap.org/data/2.5/weather?q={cityname}&appid={API_KEY}"
12
+
13
+data=requests.get(url).json()
14
+
15
+message:str=f"City: {data['name']}\nTemperature: {round(data['main']['temp']-273.15,2)} °C\nHumidity: {data['main']['humidity']}%\nDescription: {data['weather'][0]['description']}"
16
+
17
+
0
18