Untitled

 avatar
unknown
python
4 years ago
6.2 kB
4
Indexable
import os
import discord
from discord.ext import commands, tasks
import random
import asyncio
import praw
import keep_alive
from requests import get
import aiohttp
from dotenv import load_dotenv
from discord import FFmpegPCMAudio
from youtube_dl import YoutubeDL



Reddit = praw.Reddit(client_id = "",
                     client_secret = "",
                     username = "",
                     password = "",
                     user_agent = "")

load_dotenv()
client = commands.Bot(command_prefix='S!')
client.remove_command("help")



@client.command(pass_context=True)
async def meme(ctx):
    embed = discord.Embed(title="Ask, you shall receive", description="HAHA, meme go brr")

    async with aiohttp.ClientSession() as cs:
        async with cs.get('https://www.reddit.com/r/dankmemes/new.json?sort=hot') as r:
            res = await r.json()
            embed.set_image(url=res['data']['children'][random.randint(0, 25)]['data']['url'])
            await ctx.send(embed=embed)

illegal_words = ["Hitler"]

@client.event
async def on_message(message):
    if any(word in message.content for word in illegal_words):
        await message.delete()
        await message.channel.send("""this is a capitalistic word""")
    else:
        await client.process_commands(message)
   

@client.command()
async def quote(ctx):
  quotes = ["It is enough that the people know there was an election. The people who cast the votes decide nothing. The people who count the votes decide everything.", "The death of one man is a tragedy. The death of millions is a statistic.", "Ideas are more powerful than guns. We would not let our enemies have guns, why should we let them have ideas.", "Education is a weapon whose effects depend on who holds it in his hands and at whom it is aimed.", "When we hang the capitalists they will sell us the rope we use.", "Gratitude is a sickness suffered by dogs.", "You cannot make a revolution with silk gloves.", "Mankind is divided into rich and poor, into property owners and exploited; and to abstract oneself from this fundamental division; and from the antagonism between poor and rich means abstracting oneself from fundamental facts.", "History shows that there are no invincible armies.", "The writer is the engineer of the human soul.", "A sincere diplomat is like dry water or wooden iron.", "Everyone imposes his own system as far as his army can reach.", "If any foreign minister begins to defend to the death a 'peace conference', you can be sure his government has already placed its orders for new battleships and airplanes.", ""]

  await ctx.send(random.choice(quotes))




@client.command()
async def join(ctx):
    channel = ctx.message.author.voice.channel
    voice = get(client.voice_clients, guild=ctx.guild)
    if voice and voice.is_connected():
        await voice.move_to(channel)
    else:
        voice = await channel.connect()



@client.command()
async def play(ctx, url):
    YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
    FFMPEG_OPTIONS = {
        'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
    voice = get(client.voice_clients, guild=ctx.guild)

    if not voice.is_playing():
        with YoutubeDL(YDL_OPTIONS) as ydl:
            info = ydl.extract_info(url, download=False)
        URL = info['url']
        voice.play(FFmpegPCMAudio(URL, **FFMPEG_OPTIONS))
        voice.is_playing()
        await ctx.send('Bot is playing')


    else:
        await ctx.send("Bot is already playing")
        return



@client.command()
async def resume(ctx):
    voice = get(client.voice_clients, guild=ctx.guild)

    if not voice.is_playing():
        voice.resume()
        await ctx.send('Bot is resuming')

@client.command()
async def mariela(ctx):
  await ctx.send('Mariela slushai Niki ili toi shte te ddos-ne')



@client.command()
async def pause(ctx):
    voice = get(client.voice_clients, guild=ctx.guild)

    if voice.is_playing():
        voice.pause()
        await ctx.send('Bot has been paused')



@client.command()
async def stop(ctx):
    voice = get(client.voice_clients, guild=ctx.guild)

    if voice.is_playing():
        voice.stop()
        await ctx.send('Stopping...')

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_member_join(member):
    print(f'(member) has become a communist.')

@client.event
async def on_member_remove(member):
    print(f'(member) has become a capitalist.')

@client.command()
async def ping(ctx):
   await ctx.send(f'pong! {round(client.latency * 1000)}ms')

@client.command(aliases= ['purge','delete'])
@commands.has_permissions(manage_messages=True)
async def clear(ctx, amount=None): # Set default value as None
    if amount == None:
        await ctx.channel.purge(limit=1000000)
    else:
        try:
            int(amount)
        except: # Error handler
            await ctx.send('Please enter a valid integer as amount.')
        else:
            await ctx.channel.purge(limit=amount)

@client.command()
@commands.has_permissions(kick_members=True)
async def deport(ctx, member : discord.Member,*, reason=None):
    await member.kick(reason=reason)
    await ctx.send(f'{member} was deported out of Soviet Russia')

@client.command()
@commands.has_permissions(ban_members=True)
async def gulag(ctx, member : discord.Member,*, reason=None):
    await member.ban(reason=reason)
    await ctx.send(f'{member} was sent to gulag')


@client.command()
@commands.has_permissions(ban_members=True)
async def ungulag(ctx, *, member):
    banned_users = await ctx.guild.bans()
    member_name, member_discriminator = member.split("#")

    for ban_entry in banned_users:
        user = ban_entry.user

        if (user.name, user.discriminator) == (member_name, member_discriminator):
            await ctx.guild.unban(user)
            await ctx.send(f'**{user}** was freed from gulag')
            return





        





keep_alive.keep_alive()


client.run('')
Editor is loading...