-
Notifications
You must be signed in to change notification settings - Fork 16
/
rssbot.py
45 lines (39 loc) · 1.49 KB
/
rssbot.py
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
import discord
import asyncio
from pathlib import Path
import os
import time
import datetime
import aiohttp
import shutil
from config import SCREENSHOT_SAVE_PATH, RAID_IMAGE_CHANNELS, TOKEN
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
for channel in RAID_IMAGE_CHANNELS:
if message.channel.id == channel:
print(message.attachments)
print(len(message.attachments))
print(message.attachments[0]['url'])
for attachment in message.attachments:
if attachment['url'] is not None:
async with aiohttp.get(attachment['url']) as r:
if r.status == 200:
img = await r.read()
with open(attachment['filename'], 'wb') as f:
f.write(img)
print(attachment['filename'], 'saved')
file_name_save = str(attachment['filename']).replace('_', '-')
save_path = SCREENSHOT_SAVE_PATH+'/'+file_name_save
print(save_path)
shutil.move(attachment['filename'], save_path)
client.run(TOKEN)