async def gif(self, *, stag:str): """Envia um gif aleatorio com a tag escolhida !gif <tags>.""" g = safygiphy.Giphy(token='rener21BaDh2WcIgmARoUpAZcDBAGaR3') r = g.search(q=stag, limit=25) gif_dataa=r['data'] escolha = random.randint(0, 3) gif_data=gif_dataa[escolha] id=gif_data["id"] url = "https://media.giphy.com/media/"+id+"/giphy.gif" await self.bot.say(embed=discord.Embed().set_image(url=url))
def get_giphy(subject): """ Gets Giphy for command. """ #print("Subject : " + subject) #print("I am OLD") #print(type(subject)) get_obj = safygiphy.Giphy(token=GIPHY_API_KEY) rand_obj = get_obj.random(tag=subject) #print(type(rand_obj)) #print(rand_obj) if not rand_obj: return None return rand_obj['data']['images']['downsized']['url']
async def gif(self, ctx, *, tag): g = safygiphy.Giphy() tag = tag.lower() gif = g.random(tag=tag) colour = discord.Colour.from_rgb(182,7,7) em = discord.Embed(colour=colour) em.set_image(url=str(gif.get('data', {}).get('image_original_url'))) try: await ctx.send(embed=em) except discord.HTTPException: em_list = await embedtobox.etb(em) for page in em_list: await ctx.send(page)
async def socar(self, ctx, member: discord.Member = None): """Soca alguém.""" user = ctx.message.author.name if member is None: user = "******" member = ctx.message.author g = safygiphy.Giphy(token='rener21BaDh2WcIgmARoUpAZcDBAGaR3') r = g.search(q="anime punch", limit=25) gif_dataa = r['data'] gif_data = gif_dataa[random.randint(1, 20)] id = gif_data["id"] url = "https://media.giphy.com/media/" + id + "/giphy.gif" print(url) embed1 = discord.Embed(title="{0} socou {1.name}".format(user, member)) await self.bot.say(embed=embed1.set_image(url=url))
def gif_json(phrase): """ Input: string of lyrics of a line output: a json file of the top gifs related to the search uses the GIPHY API and returns the json file for 25 gifs related to the search phrase. """ url_word = phrase.replace(" ", "+") # take out spaces for url search g = safygiphy.Giphy(token='Yi4YMIrlGAlJQYnrY3vb0YljKGMiF5hM') response = g.translate(s=phrase) #print phrase + ' Wrapper ' + str(response) #data = json.loads(urllib.urlopen("http://api.giphy.com/v1/gifs/search?q=" + url_word + "&api_key=Yi4YMIrlGAlJQYnrY3vb0YljKGMiF5hM&limit=25").read()) #print phrase + ' Raw ' + str(data) #return data return response
async def gif(self, ctx, *, tag): """ Get a random lewd gif Usage: gif <tag> Available tags: rule34, nsfw, hentai, t**s... """ try: await ctx.message.delete() except discord.Forbidden: pass g = safygiphy.Giphy() gif = g.random(tag=tag) color = await ctx.get_dominant_color(ctx.author.avatar_url) em = discord.Embed(color=color) em.set_image(url=str(gif.get('data', {}).get('image_original_url'))) try: await ctx.send(embed=em) except discord.HTTPException: em_list = await embedtobox.etb(em) for page in em_list: await ctx.send(page)
def friends(): """Fotos van Vrienden.""" if request.method == "GET": # foto's van vrienden hier # init giphy api g = safygiphy.Giphy() # get the top trending gifs gif = [g.trending()["data"][x]["id"] for x in range(2, 20)] return render_template("friends.html", vrienden_photos=friend.getFriendsPhotos( session["user_id"]), gif_id=gif) else: gif_link = request.form.get("gif_link_name") gif_photo_id = request.form.get("gif_photo_name") friend.registerGif(gif_photo_id, gif_link) return redirect(url_for("friends"))
async def gif(self, ctx, *, tag): ''' Get a random gif. Usage: gif <tag> this command is sfw, to use nsfw gifs load community.nsfw ''' g = safygiphy.Giphy() tag = tag.lower() with open('data/nsfw.json')as f: nsfwgif = json.load(f) if tag in nsfwgif: return await ctx.send('`Please use the nsfw commands to see content like this.`', delete_after=5) gif = g.random(tag=tag) color = await ctx.get_dominant_color(ctx.author.avatar_url) em = discord.Embed(color=color) em.set_image(url=str(gif.get('data', {}).get('image_original_url'))) try: await ctx.send(embed=em) except discord.HTTPException: em_list = await embedtobox.etb(em) for page in em_list: await ctx.send(page)
def post(): g = safygiphy.Giphy() r = g.random(tag="science") img = r["data"]["image_original_url"] # Fill in the values noted in previous steps here cfg = { "page_id": "****", # page id in about page "access_token": "****" } api = get_api(cfg) atc = { 'name': '', 'link': img, 'caption': '', 'description': '', 'picture': img } msg = ":D #random #giphy" #post status = api.put_wall_post(message=msg, attachment=atc)
def search_giphy(self, word): '''search for gifs on giphy''' ''' ----------------------------------------------------------------------- Make outbound request to Giphy & perform a basic search - Returns list of 10 iframes containing gifs (to embed gif) NOTE: If you want the Gif ID returned instead of iframe, change line 67 to read: list_of_gifs.append(results) ----------------------------------------------------------------------- References: https://github.com/StewPoll/safygiphy https://developers.giphy.com/docs/ ----------------------------------------------------------------------- ''' # Should have dashes and not spaces if word: word = word.replace(' ', '-') # New Request Object with API Credentials giphy = safygiphy.Giphy(token=self.token) # To hold return results list_of_gifs = [] # Prefix/Suffix to Embed the results prefix = """<iframe src="https://giphy.com/embed/""" suffix = """" width="360" height="480" frameBorder="0" class="giphy-embed" allowFullScreen> </iframe>""" # Produce collection of 10 iframes containing gifs @ random by search word for _ in range(10): results = giphy.random(tag=word)["data"]["id"] embed_gifs = prefix + results + suffix # print(embed_gifs) this was to make sure correct syntax list_of_gifs.append(embed_gifs) return list_of_gifs
def on_data(self, data): # print("DATA " + data) tweet = json.loads(data.strip()) retweeted = tweet.get('retweeted', False) event = tweet.get('event', False) if 'screen_name' not in data or tweet.get('user', {}).get( 'screen_name', '') == account_user_id: from_self = True else: from_self = False if retweeted is not None and not retweeted and event is not None and not event and not from_self: tweet_id = tweet.get('id_str') screen_name = tweet.get('user', {}).get('screen_name', '') giphy = safygiphy.Giphy() gif = giphy.random(tag=random.choice(tags)) img_url = gif['data']['fixed_height_downsampled_url'] filename = img_url.split('/')[-1] urlretrieve(img_url, filename) reply_text = '@' + screen_name + " Ego te absolvo." if len(reply_text) > 140: reply_text = reply_text[0:137] + '...' api.update_with_media(filename, status=reply_text, in_reply_to_status_id=tweet_id) os.remove(filename)
import discord import asyncio import random import requests import io import safygiphy client = discord.Client() g = safygiphy.Giphy() DEIN_USERNAME = "******" minutes = 0 hour = 0 @client.event async def on_ready(): print('Eingeloggt als') print(client.user.name) print(client.user.id) print('-----------') # await client.change_presence(game=discord.Game(name="on grewoss.com")) @client.event async def on_message(message): if message.content.lower().startswith('?test'): await client.send_message(message.channel, "Test bestanden") if message.content.lower().startswith('?coin'): #Coinflip 50/50% chance kopf oder zahl choice = random.randint(1,2) if choice == 1:
import discord import safygiphy import requests import io from discord.ext import commands TOKEN = "NDY0NDU0NjU3MzEwMTk1NzEy.Dh_25Q.cq2Jyk6REUE9Kkq51qoCLxuGgZM" client = commands.Bot(command_prefix='.') g = safygiphy.Giphy(token='QeQVWnlDZG7fNtNBtB87kMhaxb2RLNsx') @client.event async def on_ready(): print('Bot is ready.') @client.command() async def ping(): await client.say('Pong!') @client.command() async def echo(*args): output = '' for word in args: output += word output += ' ' await client.say(output)
import discord import random import asyncio import requests import io import safygiphy import shelve import json import re from discord import Game client = discord.Client() legal = safygiphy.Giphy() minutos = 0 hora = 0 @client.event async def on_ready(): print(' BOT INICIADO ') print(client.user.name) print(client.user.id) print('==============') await client.change_presence(game=Game( name="Utilize ?help para saber meus comandos!")) @client.event async def on_message(message): #CRIACAO DO MENU DE HELP if message.content.lower().startswith('?help'): embed = discord.Embed(
def get_giphy(subject): g = safygiphy.Giphy() r = g.random(tag=subject) if not r: return None return r['data']['images']['downsized']['url']
def get_gif_url(imgtag): reply_img = safygiphy.Giphy() img_url = reply_img.random(tag=imgtag)['data']['image_url'] return img_url
def get_gif_url(query): giphyInstance = safygiphy.Giphy() return random.choice(giphyInstance.search(q=query)['data'])['url']
async def gif(ctx, gif: str): g = safygiphy.Giphy() rgif = g.random(tag=gif) embed = discord.Embed(color=0x00ff00) embed.set_image(url=str(rgif.get("data", {}).get('image_original_url'))) await ctx.send(embed=embed)
async def on_message(message): #Greetings and Cookies and Random Stuff if message.content.upper().startswith('HELLO!'): userID = message.author.id await client.send_message(message.channel, "Hello <@%s>!" % (userID)) if message.content.upper().startswith('YO!'): userID = message.author.id await client.send_message(message.channel, "Yo to you too, <@%s>!" % (userID)) if message.content.upper().startswith('WAZZ POPPIN!'): userID = message.author.id await client.send_message(message.channel, "Not much, <@%s>!" % (userID)) if message.content.upper().startswith('COOKIE!'): cookies = [ 'choco chip', 'vanilla', 'caramel', 'butterscotch', 'almond', 'chunky coconut', 'marmalade', 'choco lava', 'butter' ] index_cookie = random.randint(0, len(cookies) - 1) cookie_send = cookies[index_cookie] cookie_message = '{} , {} gave you a nice {} cookie :cookie: !'.format( message.content.split(' ')[1], message.author.mention, cookie_send) await client.send_message(message.channel, cookie_message) #Movies,TV Series and Video Games plot summaries if message.content.upper().startswith('MOVIE!'): userID = message.author.id args = message.content.split(" ") moviename = " ".join(args[1:]) movie = ia.search_movie(moviename) movie1 = movie[0] movieid = ia.get_imdbID(movie1) movieinfo = ia.get_movie(movieid) plot = movieinfo['plot'][0] embed = discord.Embed(title='PLOT SUMMARY', description='', colour=discord.Colour.teal()) embed.add_field(name=moviename, value=plot, inline=False) await client.send_message(message.channel, embed=embed) #Wikipedia Search if message.content.upper().startswith('WIKI!'): args = message.content.split(" ") item_search_title = " ".join(args[1:]) item_summary = wk.summary(item_search_title, sentences=4) embed = discord.Embed(title='Wikipedia Summary', description='', colour=discord.Colour.teal()) embed.add_field(name=item_search_title.capitalize(), value=item_summary, inline=False) await client.send_message(message.channel, embed=embed) #Server Info # 1.) Roles information if message.content.upper().startswith('ROLES!'): server = client.get_server(os.getenv('SERVER_ID')) roles_list = server.role_hierarchy for role in roles_list: if not role.is_everyone: embed = discord.Embed(title=role.name, description='', colour=role.colour) await client.send_message(message.channel, embed=embed) # 2.) Server information if message.content.upper().startswith('INFO!'): server = client.get_server(os.getenv('SERVER_ID')) people_count = server.member_count time_of_creation = server.created_at owner_name = server.owner.name icon = server.icon_url embed = discord.Embed(title=server.name, description='SERVER INFO', colour=discord.Colour.teal()) embed.set_thumbnail(url=icon) embed.add_field(name='Member count:', value='Humans : {}\nBots : 1'.format(people_count - 1), inline=False) embed.add_field(name='Time of Origin:', value='{}-{}-{}'.format(time_of_creation.day, time_of_creation.month, time_of_creation.year), inline=False) embed.add_field(name='Owner:', value=owner_name, inline=False) await client.send_message(message.channel, embed=embed) # 3.) Bar Plot depicting statuses of people if message.content.upper().startswith("STATUS!"): server = client.get_server(os.getenv('SERVER_ID')) if os.path.isfile('stats.png') == "True": os.remove("stats.png") mem_list = server.members online = 0 offline = 0 idle = 0 do_not_disturb = 0 invisible = 0 for mem in mem_list: if str(mem.status) == "online": online += 1 elif str(mem.status) == "offline": offline += 1 elif str(mem.status) == "idle": idle += 1 elif str(mem.status) == "dnd": do_not_disturb += 1 else: invisible += 1 stats = ('Online', 'Offline', 'Idle', 'Do Not Disturb') y_pos = np.arange(len(stats)) status_mems = [online, offline, idle, do_not_disturb] plt.bar(y_pos, status_mems, align='center', alpha=0.5, color=['green', 'grey', 'yellow', 'red']) plt.xticks(y_pos, stats) plt.yticks(np.arange(0, len((mem_list)), step=1)) plt.ylabel('Members') plt.title('Status Statistics') plt.savefig('stats.png') await client.send_file(message.channel, 'stats.png') plt.clf() #Moderation Commands # 1.) Kick a user if message.content.upper().startswith("KICK!"): server = client.get_server(os.getenv('SERVER_ID')) flag = False if message.author.server_permissions.kick_members == True and message.author.server_permissions.ban_members == True: flag = True if flag == True: for mem_ber in server.members: if mem_ber.mentioned_in(message) == True: await client.kick(mem_ber) embed = discord.Embed( title='Kicked', description="{} has been kicked from the server". format(mem_ber.mention), colour=discord.Colour.red()) await client.send_message(message.channel, embed=embed) break else: embed = discord.Embed( title='Warning', description='{} You are not allowed to use this command!'. format(message.author.mention), colour=discord.Colour.red()) await client.send_message(message.channel, embed=embed) # 2.) Ban a user if message.content.upper().startswith("BAN!"): server = client.get_server(os.getenv('SERVER_ID')) flag = False if message.author.server_permissions.kick_members == True and message.author.server_permissions.ban_members == True: flag = True if flag == True: for mem_ber in server.members: if mem_ber.mentioned_in(message) == True: await client.ban(mem_ber, 0) embed = discord.Embed( title='Banned', description="{} has been banned from the server". format(mem_ber.mention), colour=discord.Colour.red()) await client.send_message(message.channel, embed=embed) break else: embed = discord.Embed( title='Warning', description='{} You are not allowed to use this command!'. format(message.author.mention), colour=discord.Colour.red()) await client.send_message(message.channel, embed=embed) #Bot Commands Help if message.content.upper().startswith('HELP!'): embed = discord.Embed( title='SPARKY TO YOUR RESCUE!', description= 'COMMANDS [Note that the commands are case insensitive.] -->', colour=discord.Colour.teal()) embed.add_field(name='help!', value='Gives this list', inline=False) embed.add_field(name='psrules!', value='Rules of Practice Sessions', inline=False) embed.add_field(name='modhelp!', value='Moderation Commands', inline=False) embed.add_field(name='translatehelp!', value='Translation Commands', inline=False) embed.add_field(name='lrhelp!', value='Language Based Roles Commands', inline=False) embed.add_field(name='calchelp!', value='Calculator Commands', inline=False) embed.add_field(name='servhelp!', value='Server Commands', inline=False) embed.add_field(name='funhelp!', value='Fun Commands', inline=False) embed.add_field(name='utilhelp!', value='General Utility Commands help', inline=False) await client.send_message(message.channel, embed=embed) # General Utility Commands if message.content.upper().startswith('UTILHELP!'): embed = discord.Embed( title='General Utility Help', description= 'General Commands that dont belong in any other categories', colour=discord.Color.dark_grey()) embed.add_field(name='stackov! Query', value='Search for solutions to programming doubts.', inline=False) embed.add_field(name='embed! text to be embedded', value='Embeds text.', inline=False) await client.send_message(message.channel, embed=embed) #Server Related Commands if message.content.upper().startswith('SERVHELP!'): embed = discord.Embed( title='Server Commands', description= 'COMMANDS [Note that the commands are case insensitive.] -->', colour=discord.Colour.gold()) embed.add_field(name='roles!', value='Gives all the roles present in the server.', inline=False) embed.add_field(name='info!', value='Gives server info.', inline=False) embed.add_field( name='status!', value= 'Gives a plot depicting the statuses of people on the server.', inline=False) embed.add_field(name='profile!', value='Check out your profile card.', inline=False) embed.add_field(name='profile mention member!', value='Check out profile card of any member.', inline=False) embed.add_field(name='ping!', value='Ping Sparky.', inline=False) await client.send_message(message.channel, embed=embed) #Fun Commands if message.content.upper().startswith('FUNHELP!'): embed = discord.Embed( title='Fun Commands', description= 'COMMANDS [Note that the commands are case insensitive.] -->', colour=discord.Colour.magenta()) embed.add_field( name='wiki!', value='Gives brief summary from Wikipedia of the queried item', inline=False) embed.add_field(name='coin! type heads or tails', value='Make Sparky toss a coin and see if you win', inline=False) embed.add_field(name='slot!', value='Test your luck on Sparky\'s slot machine!', inline=False) embed.add_field(name='joke!', value='Cheeky and nerdy Chuck Norris jokes', inline=False) embed.add_field( name='movie! name of Movie / TV Series / Video Game', value='Gives the plot summary of the Movie/ TV series / Video Game', inline=False) embed.add_field(name='hello! / yo! / wazz poppin!', value='Sparky says hi to you', inline=False) embed.add_field(name='cookie! mention user', value='Give someone a delicious cookie', inline=False) embed.add_field(name='sparkygif! gif topic', value='Posts a GIF on the mentioned topic', inline=False) embed.add_field(name='poll! item1-without-spaces item2-without-spaces', value='Creates a 2 item poll', inline=False) embed.add_field(name='trivia!', value='Answer Sparky\'s CS trivia questions!', inline=False) await client.send_message(message.channel, embed=embed) #MOD Commands Help if message.content.upper().startswith('MODHELP!'): if message.author.server_permissions.kick_members == True and message.author.server_permissions.ban_members == True: embed = discord.Embed(title='MOD COMMANDS', description='Can be used only by Admins.', colour=discord.Colour.red()) embed.add_field(name='purge! number of messages', value='Purges through a given number of messages.', inline=False) embed.add_field(name='kick! user', value='Kicks the mentioned user from the server.', inline=False) embed.add_field(name='ban! user', value='Bans the mentioned user from the server.', inline=False) await client.send_message(message.channel, embed=embed) else: embed = discord.Embed( title='Warning', description='{} You are not allowed to use this command!'. format(message.author.mention), colour=discord.Colour.red()) await client.send_message(message.channel, embed=embed) #Practice Session Rules if message.content.upper().startswith('PSRULES!'): channel_CP = client.get_channel(os.getenv('CP_CHANNEL_ID')) role_id_list = [] for role in message.server.roles: if role.name.upper() == 'PROGRAMMERS': role_id_list.append(role.mention) if role.name.upper() == 'CODERS': role_id_list.append(role.mention) embed = discord.Embed( title='Practice Session Rules', description='To be followed by everyone who is participating', colour=discord.Colour.red()) embed.add_field( name='Rule-1', value='Post your solutions in {} using appropriate discord markdown.' .format(channel_CP), inline='False') embed.add_field( name='Rule-2', value= 'If you have a doubt, ping anyone of the support staff mentioned below. Don\'t ping the entire role', inline='False') embed.add_field( name='Rule-3', value= 'Try to make your code as efficient as possible. If you don\'t know about efficiency, leave this point.', inline='False') embed.add_field(name='Rule-4', value='Do not cheat or copy.', inline='False') embed.add_field( name='Rule-5', value= 'Use logic along with the in-built functions to get the most output.', inline='False') embed.add_field( name='Rule-6', value= 'Use C++ / C /Python / Java. If you feel excited, use Haskell or Erlang at your own risk.', inline='False') embed.add_field( name='Link for Discord Markup', value= 'https://support.discordapp.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline-', inline='False') embed.add_field(name='Support Staff', value=role_id_list[0] + '\n' + role_id_list[1], inline='False') await client.send_message(message.channel, embed=embed) #PING if message.content.upper().startswith('PING!'): start = time.time() * 1000 msg = await client.send_message(message.channel, 'PONG! :ping_pong:') end = time.time() * 1000 await client.edit_message(message=msg, new_content=':ping_pong: `{} ms`'.format( '{0:.3f}'.format(end - start))) #Coin Flip Game if message.content.upper().startswith('COIN!'): args = message.content.split(" ") result_list = ["Heads", "Tails"] choice = random.randint(0, 1) if args[1].upper() == result_list[choice].upper(): result = "{} it is! You win!".format(result_list[choice]) embed = discord.Embed(title='Coin Flip', description=result, colour=discord.Colour.teal()) await client.send_message(message.channel, embed=embed) else: result = " Uh oh, its {}! Better luck next time!".format( result_list[choice]) embed = discord.Embed(title='Coin Flip', description=result, colour=discord.Colour.teal()) await client.send_message(message.channel, embed=embed) #Slot Machine Game if message.content.upper().startswith('SLOT!'): result_list = [':apple:', ':pear:', ':tangerine:'] result_list2 = [':grapes:', ':strawberry:', ':cherries:'] result_list3 = [':hotdog:', ':icecream:', ':taco:'] choice1 = random.randint(0, 2) choice2 = random.randint(0, 2) choice3 = random.randint(0, 2) e11 = result_list[choice1] e12 = result_list[choice2] e13 = result_list[choice3] e21 = result_list2[choice1] e22 = result_list2[choice2] e23 = result_list2[choice3] e31 = result_list3[choice1] e32 = result_list3[choice2] e33 = result_list3[choice3] result = e11 + " | " + e12 + " | " + e13 + "\n" + e21 + " | " + e22 + " | " + e23 + "\n" + e31 + " | " + e32 + " | " + e33 row1 = False row2 = False row3 = False row_count = 0 if (e11 == e12) and (e12 == e13) and (e13 == e11): row1 = True row_count += 1 if (e21 == e22) and (e22 == e23) and (e23 == e21): row2 = True row_count += 1 if (e31 == e32) and (e32 == e33) and (e33 == e31): row3 = True row_count += 1 if row_count == 0: res_mes = "Better luck next time!" if row_count == 1: res_mes = "You got 1 row! Nice work!" if row_count == 2: res_mes = "You got 2 rows! Awesome!" if row_count == 3: res_mes = "Hattrick!" embed = discord.Embed(title='Slot Machine', description=result, colour=discord.Colour.teal()) embed.add_field(name='Result', value=res_mes, inline=False) await client.send_message(message.channel, embed=embed) #Joke if message.content.upper().startswith('JOKE!'): l = requests.get('http://api.icndb.com/jokes/random?limitTo=[nerdy]') l.text.split(' ') joke = eval(l.text)['value']['joke'] embed = discord.Embed(title='Joke', description=joke, colour=discord.Colour.blue()) await client.send_message(message.channel, embed=embed) #Purge Deleting Messages if message.content.upper().startswith('PURGE!'): flag = False if message.author.server_permissions.kick_members == True and message.author.server_permissions.ban_members == True: flag = True if flag == True: args = int(message.content.split(' ')[1]) print(args) await client.purge_from(message.channel, limit=args) else: embed = discord.Embed( title="Warning!", description='You are not allowed to use this command', colour=discord.Colour.red()) await client.send_message(message.channel, embed=embed) #Language Based Roles Help if message.content.upper().startswith('LRHELP!'): embed = discord.Embed(title='Language Based Roles Help', description='C/C++/Java/Python', colour=discord.Colour.purple()) embed.add_field(name='LANGROLE! name of role from above 4', value='Adds the role', inline=False) embed.add_field(name='LANGROLEREMOVE! removes role from above 4', value='Removes the role', inline=False) await client.send_message(message.channel, embed=embed) #Add Language Based Roles if message.content.upper().startswith('LANGROLE!'): lang_role_channel = client.get_channel(os.getenv('LANG_ROLE_ID')) if message.channel.id == lang_role_channel.id: arg = message.content.split(' ')[1] server = client.get_server(os.getenv('SERVER_ID')) role_member = None if arg.upper() == 'C++' or arg.upper() == 'PYTHON' or arg.upper( ) == 'C' or arg.upper() == 'JAVA': for role in server.roles: if role.name.upper() == arg.upper(): await client.add_roles(message.author, role) role_member = role break await client.delete_message(message) embed = discord.Embed( title=message.author.name, description='You have been alloted the {} role!'.format( role_member.mention), colour=role_member.colour) await client.send_message(message.channel, embed=embed) else: embed = discord.Embed( title='WARNING', description='You are not allowed to add this role.', colour=discord.Colour.red()) await client.send_message(message.channel, embed=embed) else: embed = discord.Embed( title='Warning', description='You can use this command only in {}'.format( lang_role_channel.mention), colour=discord.Colour.red()) await client.send_message(message.channel, embed=embed) #Remove Language Based Roles if message.content.upper().startswith('LANGROLEREMOVE!'): lang_role_channel = client.get_channel(os.getenv('LANG_ROLE_ID')) if message.channel.id == lang_role_channel.id: arg = message.content.split(' ')[1] server = client.get_server(os.getenv('SERVER_ID')) role_member = None if arg.upper() == 'C++' or arg.upper() == 'PYTHON' or arg.upper( ) == 'C' or arg.upper() == 'JAVA': for role in server.roles: if role.name.upper() == arg.upper(): await client.remove_roles(message.author, role) role_member = role break await client.delete_message(message) embed = discord.Embed( title=message.author.name, description='You have removed the {} role!'.format( role_member.mention), colour=role_member.colour) await client.send_message(message.channel, embed=embed) else: embed = discord.Embed( title='WARNING', description='You are not allowed to remove this role.', colour=discord.Colour.red()) await client.send_message(message.channel, embed=embed) else: embed = discord.Embed( title='Warning', description='You can use this command only in {}'.format( lang_role_channel.mention), colour=discord.Colour.red()) await client.send_message(message.channel, embed=embed) #GIFs if message.content.upper().startswith('SPARKYGIF!'): g = safygiphy.Giphy() target = message.content.split(' ')[1] gif = g.random(tag=target)['data']['url'] await client.send_message(message.channel, gif) #Profile if message.content.upper().startswith('PROFILE!'): server = client.get_server(os.getenv('SERVER_ID')) if message.content.upper() == "PROFILE!": name = message.author.name pfp = message.author.avatar_url joindate = message.author.joined_at roles = message.author.roles string = [] for item in roles: if item.name != '@everyone': string.append(item.mention) string = list(reversed(string)) string = ' '.join(string) embed = discord.Embed(title='PROFILE', description=server.name.upper(), colour=discord.Colour.teal()) embed.set_thumbnail(url=pfp) embed.add_field(name='Name:', value=name, inline='False') embed.add_field(name='Joined the server on:', value='{}-{}-{}'.format(joindate.day, joindate.month, joindate.year), inline='False') embed.add_field(name='Roles:', value=string, inline='False') await client.send_message(message.channel, embed=embed) else: for mem in server.members: if mem.mentioned_in(message) == True: name = mem.name pfp = mem.avatar_url joindate = mem.joined_at roles = mem.roles string = [] for item in roles: if item.name != '@everyone': string.append(item.mention) string = list(reversed(string)) string = ' '.join(string) embed = discord.Embed(title='PROFILE', description=server.name.upper(), colour=discord.Colour.teal()) embed.set_thumbnail(url=pfp) embed.add_field(name='Name:', value=name, inline='False') embed.add_field(name='Joined the server on:', value='{}-{}-{}'.format( joindate.day, joindate.month, joindate.year), inline='False') embed.add_field(name='Roles:', value=string, inline='False') await client.send_message(message.channel, embed=embed) break #Translate Commands if message.content.upper().startswith('TRANSLATE!'): args = ' '.join(message.content.split(' ')[2::]) lang = message.content.split(' ')[1] translations = translator.translate(args, dest=lang) embed = discord.Embed(title='SPARKY TRANSLATE', description='Sparky Translates for you!', colour=discord.Colour.teal()) embed.add_field(name='Original Message:', value=args, inline='False') embed.add_field(name='Translated Message:', value=translations.text, inline='False') await client.send_message(message.channel, embed=embed) if message.content.upper().startswith('TRANSLATELANGS!'): msg = dict(map(reversed, LANGUAGES.items())) args = message.content.split(' ')[1] languages = list(msg.keys()) if args.lower() in languages: embed = discord.Embed(title=args.lower(), description='The Code is: {}'.format( msg[args.lower()]), colour=discord.Colour.teal()) await client.send_message(message.channel, embed=embed) else: embed = discord.Embed(title='Warning!', description='This language is not available', colour=discord.Colour.teal()) await client.send_message(message.channel, embed=embed) if message.content.upper().startswith('TRANSLATEHELP!'): embed = discord.Embed(title='Sparky Translation Help', description='Commands', colour=discord.Colour.teal()) embed.add_field(name='translatelangs! language', value='Gives the code of the language asked', inline='False') embed.add_field( name='translate! languagecode message to be translated', value='Translates the given message into the selected language.', inline='False') await client.send_message(message.channel, embed=embed) #Calculator if message.content.upper().startswith('CALC!'): args = message.content.split(' ') res = 0 if args[1].upper() == 'SIN': res = math.sin(math.radians(float(args[2]))) elif args[1].upper() == 'COS': res = math.cos(math.radians(float(args[2]))) elif args[1].upper() == 'TAN': res = math.tan(math.radians(float(args[2]))) elif args[1].upper() == 'EXP': res = math.exp(float(args[2])) elif args[1].upper() == 'POW': res = math.pow(float(args[2]), float(args[3])) elif args[1].upper() == 'SQRT': if float(args[2]) >= 0: res = math.sqrt(float(args[2])) else: res = "Mathematical Error!" elif args[1].upper() == 'LOG': if float(args[2]) > 0 and float(args[3]) > 0: res = math.log(float(args[2]), float(args[3])) else: res = "Mathematical Error!" elif args[1].upper() == 'EVAL': s = ''.join(args[2:]) res = eval(s) else: res = 'Wrong Command!' embed = discord.Embed(title='Sparky\'s Calculator', description='Answer', colour=discord.Colour.orange()) embed.add_field(name=' '.join(args[1:]), value=res, inline='False') await client.send_message(message.channel, embed=embed) if message.content.upper().startswith('CALCHELP!'): embed = discord.Embed(title='Sparky\'s Calculator', description='Quick Maths', colour=discord.Colour.orange()) embed.add_field(name='calc! sin/cos/tan angle', value='Sine/Cosine/Tangent of the given angle', inline='False') embed.add_field(name='calc! exp number', value='Exp(number)', inline='False') embed.add_field(name='calc! log value base', value='Log of value to the given base', inline='False') embed.add_field(name='calc! sqrt number', value='Square root of number', inline='False') embed.add_field(name='calc! pow number exponent', value='Value of number raised to exponent', inline='False') embed.add_field(name='calc! eval expression_without_spaces', value='Value of the expression', inline='False') await client.send_message(message.channel, embed=embed) #Poll if message.content.upper().startswith('POLL!'): args = message.content.split(' ')[1:] item1 = args[0] item2 = args[1] embed = discord.Embed( title='POLL', description='A poll has been created by {}!'.format( message.author.mention), colour=discord.Colour.blue()) embed.add_field(name=':one: {}'.format(item1.upper()), value='React with :one: to vote', inline=False) embed.add_field(name=':two: {}'.format(item2.upper()), value='React with :two: to vote', inline=False) msg = await client.send_message(message.channel, embed=embed) await client.add_reaction(msg, '\U00000031\U000020e3') await client.add_reaction(msg, '\U00000032\U000020e3') # Stackoverflow Search if message.content.upper().startswith('STACKOV!'): args = ' '.join(message.content.split(' ')[1:]) query = search('Stackoverflow ' + args) embed = discord.Embed(title='StackOverflow Search', description='Results for the query', colour=discord.Color.orange()) print('Stackoverflow ' + args) for item in query: embed.add_field(name='-->', value=item, inline=False) await client.send_message(message.channel, embed=embed) # Embed Text if message.content.upper().startswith('EMBED!'): args = ' '.join(message.content.split(' ')[1:]) embed = discord.Embed(title='Embedded by {}'.format( message.author.name), description=args, colour=discord.Color.dark_orange()) await client.send_message(message.channel, embed=embed) #Trivia if message.content.upper().startswith("TRIVIA!"): req = requests.get( "https://opentdb.com/api.php?amount=1&category=18&type=multiple") texts = ast.literal_eval(req.text) question = texts["results"][0]["question"] cor_ans = texts["results"][0]["correct_answer"] incorrect_answers = texts["results"][0]["incorrect_answers"] incorrect_answers.append(cor_ans) answers_lis = incorrect_answers random.shuffle(answers_lis) embed = discord.Embed( title="CS TRIVIA by Sparky", description="Type a number between 1 and 4 to choose your answer.", colour=discord.Color.dark_teal()) embed.add_field(name='Question', value=question, inline=False) embed.add_field(name=':one:', value=answers_lis[0], inline=False) embed.add_field(name=':two:', value=answers_lis[1], inline=False) embed.add_field(name=':three:', value=answers_lis[2], inline=False) embed.add_field(name=':four:', value=answers_lis[3], inline=False) await client.send_message(message.channel, embed=embed) msg = await client.wait_for_message(author=message.author, channel=message.channel) options = ["1", "2", "3", "4"] if msg.content in options: if answers_lis[int(msg.content) - 1] == cor_ans: embed = discord.Embed( title="Correct Answer!", description= "{} has answered the question correctly, the answer is Option-{} : {}!" .format(message.author.name, msg.content, cor_ans), colour=discord.Color.green()) await client.send_message(message.channel, embed=embed) else: embed = discord.Embed( title="Wrong Answer!", description= "{} has answered the question wrong, the correct answer is Option-{} : {}!" .format(message.author.name, answers_lis.index(cor_ans) + 1, cor_ans), colour=discord.Color.red()) await client.send_message(message.channel, embed=embed) else: embed = discord.Embed( title="Warning!", description= "Type a number between 1 and 4 only (both inclusive)!", colour=discord.Color.red()) await client.send_message(message.channel, embed=embed)
def getMember(name): g = safygiphy.Giphy() r = g.random(tag=name) return render_template('test.html', name=name, url_gif=r["data"]["id"])
#!/usr/bin/env python # -*- coding: iso-8859-1 -*- import safygiphy from response import Response giief = safygiphy.Giphy() def getgif(mattermost_request): text = mattermost_request.text search = ''.join(text).encode('latin1') jif = giief.random(tag=search) if jif['data']: t = u'' + jif['data']['image_original_url'] + " " + search.decode( 'utf-8') else: t = "gibts nicht" return Response(t)
import asyncio import io import discord import requests import sys import keys import random import pxldrn import safygiphy client = discord.Client() mods = open("pxldrn/adv/config/mods.txt", "r", encoding='utf-8') players = {} p_volume = {} gif = safygiphy.Giphy() @client.event async def on_ready(): print('Eingeloggt als') print(client.user.name) print(client.user.id) print('------------------------') await client.change_presence(game=discord.Game( name='mit p.help', url="http://twitch.tv/pixeldrohne", type=1)) @client.event async def on_message(message): # Spielstatus