Skip to content

Instantly share code, notes, and snippets.

@max-kov
Created June 22, 2017 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save max-kov/dcbc8047a00d4defa70ca9590bfe6940 to your computer and use it in GitHub Desktop.
Save max-kov/dcbc8047a00d4defa70ca9590bfe6940 to your computer and use it in GitHub Desktop.
my bot for discord i made, sensitive data replaced with --...--
from cleverwrap import CleverWrap
import discord
from discord.ext.commands import Bot
import wolframalpha
at_max_id = "--MY ID--"
at_bot_id = "--BOT ID--"
cb = CleverWrap("--cb id--")
token = "--chat token--"
my_bot = Bot(command_prefix="!")
my_bot.last_msg_channel = None
waclient = wolframalpha.Client("--wa app id--")
@my_bot.command()
async def calc(query):
res = waclient.query(query)
if res["@success"]!="false":
for pod in res.pods:
for sub in pod.subpods:
if sub["plaintext"]!= None:
await my_bot.say(sub["@title"]+" "+sub["plaintext"])
else:
em = discord.Embed(title=sub["@title"])
em.set_image(url=sub["img"]["@src"])
await my_bot.say(embed=em)
else:
await my_bot.say("i dont get it, did you mean:")
for pod in res["didyoumeans"]["didyoumean"]:
await my_bot.say(pod["#text"])
@my_bot.command()
async def log():
em = discord.Embed()
em.set_image(url="http://images2.fanpop.com/image/photos/14200000/Haibara-Ai-ai-haibara-14288045-640-480.jpg")
await my_bot.say(embed=em)
@my_bot.command(pass_context=True)
async def joined_at(ctx, member: discord.Member = None):
if member is None:
member = ctx.message.author
await my_bot.say('{0} joined at {0.joined_at}'.format(member))
@my_bot.command()
async def repeat(data:str, times=1):
new_data = data
new_data = new_data.replace(at_max_id,"max")
new_data = new_data.replace(at_bot_id,"maxs bot")
new_data = new_data.replace("!","")
if times>10:
times=10
for i in range(times):
await my_bot.say(new_data)
@my_bot.command()
async def kys(*args):
await my_bot.say("k :C")
await my_bot.logout()
@my_bot.command()
async def change_channel(name:str):
for chn in my_bot.get_all_channels():
if name == chn.name:
my_bot.last_msg_channel = chn
@my_bot.event
async def on_message(message):
msg = str(message.content)
at_max = msg.find(at_max_id)!=-1
at_bot = msg.find(at_bot_id)!=-1
if message.author != my_bot.user and not message.content.startswith('!') and (at_bot or at_max) and \
not message.channel.is_private:
if at_max:
new_msg = msg.replace(at_max_id, "")
if at_bot:
new_msg = msg.replace(at_bot_id, "")
response = cb.say(str(new_msg))
my_bot.last_msg_channel = message.channel
await my_bot.send_message(message.channel, response)
if message.author != my_bot.user and message.channel.is_private and not message.content.startswith('!'):
if my_bot.last_msg_channel!=None:
await my_bot.send_message(my_bot.last_msg_channel,message.content)
else:
await my_bot.send_message(message.channel, "dude, where do i say it? (use !change_channel --channel_name--)")
await my_bot.process_commands(message)
cb.reset()
my_bot.run(token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment