-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
140 lines (108 loc) · 3.51 KB
/
bot.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
TOKEN = "NTc5MzgzNjE5OTMyNTIwNDU4.XOUtnA.DkCX2WxYKtpuaTDwoI2ORbCmKuo"
import settings
import os
from modules import news, image, flip_a_coin, roll_a_dice, shorten_url
import discord
from discord.ext import commands
from modules import xkcd
from modules import lyrics,video
bot = commands.Bot(
command_prefix="$",
description="Just A Rather Very Intelligent System, now on Discord!",
)
@bot.event
async def on_ready():
print("Logged in as")
print(bot.user.name)
print(bot.user.id)
print("------")
@bot.command()
async def greet(ctx):
await ctx.send(":smiley: :wave: Hello, there!")
@bot.command(
name="xkcd",
description="Retrieves a random xkcd comic through external API call",
brief="Retrieves a random xkcd comic",
)
async def get_xkcd(ctx):
try:
embed = xkcd.process()
await ctx.send(embed=embed)
except Exception as e:
print(e)
await ctx.send("Sorry, something went wrong.")
@bot.command(
name="news",
description="Retrieves a random top headline from NewsAPI",
brief="Retrieves a top headline",
)
async def cmd_news(ctx):
await ctx.send(embed=news.top_headlines())
@bot.command(
name="image",
description="Searches an image from google search engine",
brief="Search an image",
)
async def search_image(ctx, search_arg):
try:
embed = await image.process(search_arg)
await ctx.send(embed=embed)
except Exception as e:
print(e)
await ctx.send("Sorry, something went wrong.")
@bot.command(
name="flip_a_coin",
description="Flip a coin game",
brief="flip a coin and send head to tails",
)
async def flip_coin(ctx):
try:
embed = flip_a_coin.coinToss()
await ctx.send(embed=embed)
except Exception as e:
print(e)
await ctx.send("Sorry, something went wrong.")
@bot.command(
name="roll_a_dice",
description="Flip a coin game",
brief="flip a coin and send head to tails",
)
async def roll_dice(ctx):
try:
embed = roll_a_dice.rollDice()
await ctx.send(embed=embed)
except Exception as e:
print(e)
await ctx.send("Sorry, something went wrong.")
@bot.command(
name="shorturl",
description="shorten a given url",
brief="Short a url",
)
async def short_url(ctx, search_arg):
try:
embed = shorten_url.urlShortner(search_arg)
await ctx.send(embed=embed)
except Exception as e:
print(e)
await ctx.send("Sorry, something went wrong.")
@bot.command(pass_context=True, name='lyrics')
async def get_lyrics(ctx, *, message):
try:
output = lyrics.process(message)
r = str(output['output']).replace('{', '').replace('}', '')
r = r.replace('\'text\':', '').replace('\'', '')
r = r.replace('\\n', '\n').replace('"', '')
await ctx.send(r)
except Exception as e:
print(e)
await ctx.send("Sorry, something went wrong.")
@bot.command(pass_context=True, name='video')
async def get_video(ctx, *, message):
try:
output = video.process(message)
await ctx.send(output['output'])
except Exception as e:
print(e)
await ctx.send("Sorry, something went wrong.")
bot.run(TOKEN)