Compare commits
12
Commits
2279ae700c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cf83daf0b | ||
|
|
7811ee2888 | ||
|
|
139a5ad956 | ||
|
|
d4502bed84 | ||
|
|
c7adb15c86 | ||
|
|
dc763d54c1 | ||
|
|
ecd0ca09ea | ||
|
|
4a633809f8 | ||
|
|
556be5fbe6 | ||
|
|
34aed5421a | ||
|
|
dbad01da5c | ||
|
|
ce8e09f4ab |
+1
-1
@@ -4,6 +4,6 @@ ENV PATH=/usr/local/bin:$PATH
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*
|
||||||
COPY . .
|
COPY . .
|
||||||
CMD ["python", "-u", "main.py"]
|
CMD ["python", "-u", "main.py"]
|
||||||
@@ -55,7 +55,7 @@ async def post_reddit_periodically():
|
|||||||
async def get_latest_post(subreddit):
|
async def get_latest_post(subreddit):
|
||||||
post_limit = os.getenv("POST_LIMIT", 20)
|
post_limit = os.getenv("POST_LIMIT", 20)
|
||||||
url = f"https://www.reddit.com/r/{subreddit}/hot.rss?limit={post_limit}"
|
url = f"https://www.reddit.com/r/{subreddit}/hot.rss?limit={post_limit}"
|
||||||
headers = {"User-Agent": "Mozilla/5.0 (compatible; ich_iel-Bot/0.6.2)"}
|
headers = {"User-Agent": "Mozilla/5.0 (compatible; ich_iel-Bot/1.0.1)"}
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
logging.error(f"Failed to fetch RSS feed: {response.status_code}")
|
logging.error(f"Failed to fetch RSS feed: {response.status_code}")
|
||||||
@@ -121,7 +121,7 @@ async def setChannel(message):
|
|||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def version(message):
|
async def version(message):
|
||||||
await message.channel.send("Version 0.6.2 is running\nSource code: https://github.com/michelleDeko/ich_iel-bot")
|
await message.channel.send("Version 1.0.1 is running\nSource code: https://github.com/michelleDeko/ich_iel-bot")
|
||||||
|
|
||||||
# the cat bot died, so i wanted to add this command to this bot
|
# the cat bot died, so i wanted to add this command to this bot
|
||||||
@bot.command()
|
@bot.command()
|
||||||
@@ -150,6 +150,7 @@ async def dog(message):
|
|||||||
await message.channel.send("Failed to fetch dog image")
|
await message.channel.send("Failed to fetch dog image")
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
|
@bot.command("fops")
|
||||||
async def fox(message):
|
async def fox(message):
|
||||||
response = requests.get("https://randomfox.ca/floof/")
|
response = requests.get("https://randomfox.ca/floof/")
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
@@ -163,6 +164,8 @@ async def fox(message):
|
|||||||
|
|
||||||
# time for racoons
|
# time for racoons
|
||||||
@bot.command()
|
@bot.command()
|
||||||
|
@bot.command("raccoon")
|
||||||
|
@bot.command("coon")
|
||||||
async def racoon(message):
|
async def racoon(message):
|
||||||
urls = random.choice([
|
urls = random.choice([
|
||||||
"https://api.mapach.es/v1/meme",
|
"https://api.mapach.es/v1/meme",
|
||||||
@@ -179,6 +182,8 @@ async def racoon(message):
|
|||||||
# i just watched beastars and i realised that this bot needs a bnuy command
|
# i just watched beastars and i realised that this bot needs a bnuy command
|
||||||
# maybe I will switch the API later since this one seems to only have gifs
|
# maybe I will switch the API later since this one seems to only have gifs
|
||||||
@bot.command()
|
@bot.command()
|
||||||
|
@bot.command("bnuuy")
|
||||||
|
@bot.command("bunny")
|
||||||
async def bnuy(message):
|
async def bnuy(message):
|
||||||
urls = random.choice([
|
urls = random.choice([
|
||||||
"https://api.bunnies.io/v2/loop/random/?media=gif,png",
|
"https://api.bunnies.io/v2/loop/random/?media=gif,png",
|
||||||
@@ -209,6 +214,32 @@ async def bnuy(message):
|
|||||||
file_ext = content_type.split("/")[-1] if content_type.startswith("image/") else "jpg"
|
file_ext = content_type.split("/")[-1] if content_type.startswith("image/") else "jpg"
|
||||||
await message.channel.send(file=fluxer.File(image_bytes, filename=f"bnuy.{file_ext}"))
|
await message.channel.send(file=fluxer.File(image_bytes, filename=f"bnuy.{file_ext}"))
|
||||||
|
|
||||||
|
@bot.command()
|
||||||
|
@bot.command("capy")
|
||||||
|
async def capybara(message):
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
async with session.get("https://api.capy.lol/v1/capybara?json=true") as response:
|
||||||
|
if response.status != 200:
|
||||||
|
await message.channel.send("Failed to fetch image of a bunny")
|
||||||
|
return
|
||||||
|
data = await response.json()
|
||||||
|
|
||||||
|
image_url = (
|
||||||
|
data.get("data", {}).get("url")
|
||||||
|
)
|
||||||
|
if not image_url:
|
||||||
|
await message.channel.send("Failed to fetch image of a capybara")
|
||||||
|
return
|
||||||
|
|
||||||
|
async with session.get(image_url) as image_response:
|
||||||
|
if image_response.status != 200:
|
||||||
|
await message.channel.send("Failed to fetch image of a capybara")
|
||||||
|
return
|
||||||
|
image_bytes = await image_response.read()
|
||||||
|
content_type = image_response.headers.get("Content-Type", "").split(";")[0]
|
||||||
|
file_ext = content_type.split("/")[-1] if content_type.startswith("image/") else "jpeg"
|
||||||
|
await message.channel.send(file=fluxer.File(image_bytes, filename=f"capybara.{file_ext}"))
|
||||||
|
|
||||||
async def post_reddit():
|
async def post_reddit():
|
||||||
subreddit = os.getenv("SUBREDDIT", "ich_iel")
|
subreddit = os.getenv("SUBREDDIT", "ich_iel")
|
||||||
posts = await get_latest_post(subreddit)
|
posts = await get_latest_post(subreddit)
|
||||||
@@ -238,7 +269,18 @@ async def post_reddit():
|
|||||||
channel = await bot.fetch_channel(int(channel_id))
|
channel = await bot.fetch_channel(int(channel_id))
|
||||||
if channel:
|
if channel:
|
||||||
if await check_guild(guild_id):
|
if await check_guild(guild_id):
|
||||||
await channel.send(f"{title}\nOriginal post: {image_url}")
|
async with aiohttp.ClientSession() as session:
|
||||||
|
async with session.get(image_url) as response:
|
||||||
|
if response.status != 200:
|
||||||
|
logging.error(f"Failed to fetch image from {image_url}: {response.status}")
|
||||||
|
continue
|
||||||
|
image_bytes = await response.read()
|
||||||
|
content_type = response.headers.get("Content-Type", "").split(";")[0]
|
||||||
|
file_ext = content_type.split("/")[-1] if content_type.startswith("image/") else "jpg"
|
||||||
|
await channel.send(
|
||||||
|
content=f"{title}\nOriginal post: <{image_url}>",
|
||||||
|
file=fluxer.File(image_bytes, filename=f"{post_id}.{file_ext}")
|
||||||
|
)
|
||||||
cur.execute("INSERT OR REPLACE INTO posted (guild_id, post_id) VALUES (?, ?)", (guild_id, post_id))
|
cur.execute("INSERT OR REPLACE INTO posted (guild_id, post_id) VALUES (?, ?)", (guild_id, post_id))
|
||||||
con.commit()
|
con.commit()
|
||||||
logging.info(f"Posted to channel {channel_id} in guild {guild_id}")
|
logging.info(f"Posted to channel {channel_id} in guild {guild_id}")
|
||||||
|
|||||||
Reference in New Issue
Block a user