-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
100 lines (73 loc) · 2.91 KB
/
main.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
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
import urllib.request, json
import discord
import random
from random import *
from discord.ext import commands
from discord.ext import tasks
from itertools import cycle
from discord.ext.commands import has_permissions, MissingPermissions
from discord import Member
from traceback import format_exception
import io
import contextlib
from io import BytesIO
from pprint import pprint
import os
from dotenv import load_dotenv
import textwrap
import asyncio
import json
import datetime
import random as r
client = commands.Bot(command_prefix ="c!", intents=discord.Intents.all())
@client.event
async def on_ready():
print("ready")
@client.command()
async def joke(ctx):
"""get a chuck norris joke"""
with urllib.request.urlopen("http://api.icndb.com/jokes/random") as url:
data = json.loads(url.read().decode())
value = data["value"]
joke = uwu["joke"]
await ctx.reply(joke)
@client.command()
async def bored(ctx):
"""Get an activity to do"""
with urllib.request.urlopen("https://www.boredapi.com/api/activity") as url:
data = json.loads(url.read().decode())
activity = data["activity"]
await ctx.reply(activity)
@client.command()
async def reddit(ctx, *, sub="memes"):
"""Reddit API integration"""
with urllib.request.urlopen(f"https://www.reddit.com/r/{sub}/new.json") as url:
jsondata = json.loads(url.read().decode())
data = jsondata["data"]
children = data["children"]
postnum = r.randint(0, 24)
post = children[postnum]
postdata = post["data"]
nsfwcheck = postdata["over_18"]
if nsfwcheck == True:
await ctx.reply("post gathered was NSFW!")
else:
name = postdata["title"]
link = postdata["url"]
content = postdata["selftext"]
image = postdata["thumbnail"]
creator = postdata["author"]
embed = discord.Embed(
title=f"{name}",
description=f"{content}",
url=link,
colour=discord.Colour.blurple()
)
try:
embed.set_image(url = postdata["url_overridden_by_dest"])
except:
pass
embed.set_footer(text="Post by " + creator)
embed.set_author(name="Videos and galleries (multiple images 1 post) are NOT supported!")
await ctx.reply(embed=embed)
client.run("token")