-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
175 lines (151 loc) · 6.02 KB
/
main.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import os
# import random
from bs4 import BeautifulSoup
import discord
import requests
from dotenv import load_dotenv
from alive import keep_alive
from discord.ext import commands
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
api_dev_key=os.getenv('api_dev_key')
api_user_key=os.getenv('api_user_key')
intents = discord.Intents.default()
import json
api_paste_key = os.getenv('API_PASTE_KEY')
intents.members=True
# client = discord.Client(intents=intents)
bot = commands.Bot(command_prefix='!',intents=intents)
def pull_paste_backfunc():
url="https://pastebin.com/api/api_raw.php"
api_option='show_paste'
data={
'api_dev_key':api_dev_key,
'api_user_key':api_user_key,
'api_paste_key':api_paste_key,
'api_option':api_option
}
r=requests.post(url,data=data)
return r.text
def list_pastes_backend():
url="https://pastebin.com/api/api_post.php"
api_option='list'
data={
'api_dev_key':api_dev_key,
'api_user_key':api_user_key,
'api_option':api_option
}
r=requests.post(url,data=data)
# res=r.text
return r.text
#--------------------------------------------------
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print(bot.guilds)
print('------')
await bot.change_presence(status=discord.Status.idle,activity=discord.Activity(type=discord.ActivityType.listening, name="!help"))
# chal=discord.utils.get(server.channels,name='general')
# chal=bot.get_channel(788505937693900823)
# await chal.send("Hello!!")
# await chal.send("Hydra chutiyo ki nhi sunta!! Ashvin")
# await bot.change_presence(status=discord.Status.idle, activity=activity)
#--------------------------------------------------
@bot.command()
async def repeat(ctx, times: int, content,category='General'):
"""Repeats a message multiple times."""
for i in range(times):
await ctx.send(content)
@bot.command(name='hello',help="Just informal Hello!!")
async def hello_func(ctx):
await ctx.send("Ram Ram vhiya!!")
# @bot.command(name='stp',help='Stone Paper Scissor classic game.')
# async def stone_paper(ctx):
# options_stone_paper=["stone","paper","scissor"]
# await ctx.send("Let's Start the Game!! Enter your move.")
# arg = await bot.wait_for('message')
# bot_chance=random.choice(options_stone_paper)
# if arg==bot_chance:
# await ctx.send("I also said "+bot_chance+"!!")
# else:
# if arg==options_stone_paper[0] and bot_chance==options_stone_paper[1]:
# await ctx.send("Bot Wins")
# elif arg==options_stone_paper[0] and bot_chance==options_stone_paper[2]:
# await ctx.send("User Wins!!")
# elif arg==options_stone_paper[1] and bot_chance==options_stone_paper[0]:
# await ctx.send("User Wins!!")
# elif arg==options_stone_paper[1] and bot_chance==options_stone_paper[2]:
# await ctx.send("Bot Wins!!")
# elif arg==options_stone_paper[2] and bot_chance==options_stone_paper[0]:
# await ctx.send("Bot Wins!!")
# elif arg==options_stone_paper[2] and bot_chance==options_stone_paper[1]:
# await ctx.send("User Wins!!")
# else:
# await ctx.send(arg.text)
#--------------------------------------------------
@bot.event
async def on_member_join(member):
# chal=bot.get_channel(788505937693900823)
chal=discord.utils.get(member.guilds.channel,name='general').id
embed=discord.Embed(title=f"Welcome {member.name}",description=f"Have Fun in {member.guild.name}!")
embed.set_thumbnail(url='https://images.unsplash.com/photo-1444703686981-a3abbc4d4fe3?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80')
await chal.send(embed=embed)
#--------------------------------------------------
@bot.command(name='create-channel',help='Creates a channel with given name')
@commands.has_role('Admin'or 'Lal')
async def create_channel(ctx,channel_name):
guild=ctx.guild
category = ctx.guild.category
existing_channel=discord.utils.get(guild.channels,channel_name)
if not existing_channel:
await ctx.send(f"Creating channel {channel_name}!!")
# await ctx.guild.create_category(channel_cataegory, overwrites=None)
await ctx.guild.create_text_channel(channel_name,category=category,overwrites=None,reason=None)
# else:
# await ctx.send("lal!")
#--------------------------------------------------
@bot.command(name='insult',help="Tell me the name of User who annoys you, I'll take care of it.",category='Toxic')
async def insult(ctx,user: discord.Member):
if user.name==bot.user.name:
await ctx.send(f"{ctx.author.mention} Bade harami ho beta!!")
else:
url = "https://evilinsult.com/generate_insult.php"
params = {
'lang': 'en',
'type': 'json'
}
r = requests.get(url, params=params)
ticktok = r.json()
await ctx.send(f"{user.mention} " +ticktok['insult'])
#--------------------------------------------------
@bot.command(name='pull-paste',help='Retrieve Pastebin paste.Still Developing')
async def pull_paste(ctx):
await ctx.send("Getting your paste!!")
await ctx.send('`'+pull_paste_backfunc()+'`')
@bot.command(name='list-pastes')
async def list_pastes(ctx):
res=list_pastes_backend()
soup=BeautifulSoup(res,'html.parser')
paste_key,paste_title=soup.paste.paste_key.string, soup.paste.paste_title.string
await ctx.send("Pastes are:\n")
await ctx.send("`Paste Title: "+paste_title+"\nPaste key: " +paste_key+'`')
def get_response_from_bot(text):
link = 'https://app.aimarketplace.co/api/marketplace/models/382d1f69-2fed-4e15-a626-2c1909d66225/predict/'
inp = text
header = {'Authorization': 'Api-Key dACeYg0d.ZzIQ9Ey5ADD23FAG4H1CcdM6dsUzsHsr'}
payload = {'data':inp}
request = requests.request('POST',link, data=payload, headers=header)
print(request.text)
t = json.loads(request.text)
return t['output']['Response']
@bot.command(name='ask')
async def ask(ctx, *,text):
print(text)
t = get_response_from_bot(text)
await ctx.send(f"` {t}`")
keep_alive() #this function is important to be upar than bot.run(token)
bot.run(TOKEN)
# client.run(TOKEN)