forked from boviex/feubot
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfeubot_local.py
125 lines (108 loc) · 4.75 KB
/
feubot_local.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
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
import discord
from discord.ext import commands
import asyncio
import re
import random
import urllib
import urllib.request
import urllib.error
import os
import json
bot = commands.Bot(command_prefix=['##', 'feubeta '], description='this is feubot.')
def trunc_to(ln, s):
if len(s) >= ln: return s
else: return s[:ln-3] + "..."
def create_embed(posts, threads, term):
feu_search_base = "http://feuniverse.us/search?q=%s"
feu_post_base = "http://feuniverse.us/t/{}/{}"
result = discord.Embed(
title="Search results",
url=feu_search_base % term,
description="Found %d results" % len(posts),
color=0xde272c)
for i,post in enumerate(posts[:5]):
result.add_field(
name='Post in "%s" by %s' % (threads[i]["title"], post["name"]),
value="[%s](%s)" %
(trunc_to(50, post["blurb"]),
feu_post_base.format(post["topic_id"], post["post_number"])),
inline=False)
if len(posts) > 5:
result.set_footer(text="Truncated %d result(s)." % (len(posts)-5))
return result
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
await bot.change_presence(game=discord.Game(name="Reading the doc!"))
@bot.command()
async def search(*, term):
"""search feu"""
root = "http://feuniverse.us/search.json?q=%s"
payload = urllib.parse.quote(term)
with urllib.request.urlopen(root % payload) as query:
try:
data = json.loads(query.read().decode())
posts = data["posts"]
threads = data["topics"]
await bot.say(embed=create_embed(posts, threads, payload))
except urllib.error.URLError:
await bot.say("Error accessing FEU server, please try again later.")
@bot.command()
async def donate():
"""you know it"""
await bot.say("https://donorbox.org/donate-to-circles")
@bot.command()
async def UT2():
"""links ultimate tutorial v2"""
await bot.say("https://stackedit.io/viewer#!provider=gist&gistId=084645b0690253600f4aa2a57b76a105&filename=feutv2")
@bot.command()
async def reply():
"""r e p l y s o o n"""
await bot.say("reply :soon: :smile:")
@bot.command()
async def fuckingincredible():
"""fuckingincredible.png"""
await bot.say("http://i.imgur.com/yt4hXhJ.png")
@bot.command()
async def arch():
"""do something with arch"""
direction = random.choice([":arrow_down:", ":arrow_up:"])
await bot.say(direction+" with <:arch_mini:230160993299202068>")
@bot.command()
async def goofs():
"""list goofs"""
await bot.say("```"+"\n".join(map(str, os.listdir("./goofs")))+"```")
@bot.command()
async def goof(*args):
"""show goof"""
requested = args
gooflist = os.listdir("./goofs")
if len(requested) != 0:
for request in requested:
if request in gooflist:
await bot.upload("./goofs/"+request)
else:
await bot.say("Use >>goofs to see a list of accepted goofs.")
else:
await bot.upload("./goofs/"+random.choice(gooflist))
@bot.command()
async def erin():
"""ERIN INTENSIFIES"""
await bot.upload("./erinyous.gif")
@bot.command()
async def fury():
"""2 FAST 2 FURYOUS"""
await bot.say("Don't you mean `>>erin`?")
@bot.command()
async def doot():
"""doot doot"""
await bot.say("""<:doot:324593825815461889> <:doot:324593825815461889> :trumpet: :trumpet: :trumpet: <:doot:324593825815461889> :trumpet: :trumpet: :trumpet: <:doot:324593825815461889> :trumpet: :trumpet: <:doot:324593825815461889> <:doot:324593825815461889> <:doot:324593825815461889>
<:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: :trumpet: <:doot:324593825815461889> :trumpet:
<:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: :trumpet: <:doot:324593825815461889> :trumpet:
<:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: <:doot:324593825815461889> :trumpet: :trumpet: <:doot:324593825815461889> :trumpet:
<:doot:324593825815461889> <:doot:324593825815461889> :trumpet: :trumpet: :trumpet: <:doot:324593825815461889> :trumpet: :trumpet: :trumpet: <:doot:324593825815461889> :trumpet: :trumpet: :trumpet: <:doot:324593825815461889> :trumpet:""")
# bot.run(os.environ['TOKEN'])
bot.run(open('./token','r').read().replace('\n', ''))