forked from puang59/lewdWaifu.im
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmassSupply.py
132 lines (116 loc) · 4.96 KB
/
massSupply.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
from asyncio import tasks
import discord
import aiohttp
import asyncio
import os
import sys
import random
from datetime import datetime
from discord.ext import commands, tasks
intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix=["!","?"], case_insensitive=True, intents=intents)
# with open('cred.txt', 'r') as f:
# global token
# token = f.read()
token = os.environ['TOKEN']
async def main():
async with bot:
supply.start()
print('Supply started!')
await bot.start(token)
def restart_bot():
os.execv(sys.executable, ['python'] + sys.argv)
@bot.command()
async def restart(ctx):
if ctx.message.author.id == 852797584812670996:
await ctx.send("Restarted!")
restart_bot()
else:
await ctx.send("You cannot use this command!")
@tasks.loop(minutes=30)
async def supply():
await bot.wait_until_ready()
# putang = ctx.guild.get_member(852797584812670996)
# deory = ctx.guild.get_member(409994220309577729)
# if ctx.message.author.id == 852797584812670996:
# await ctx.message.delete()
guild = bot.get_guild(1006254992648327290)
pause_role = guild.get_role(1010788120511381524)
i = 0
while i < 10:
wpic = "https://api.waifu.pics/nsfw/waifu" #waifu.pics url
wim = "https://api.waifu.im/random/?" \
"&gif=false" \
"&is_nsfw=true" # waifu.im url
url = random.choice([wim, wpic])
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
res = await response.json()
for member in guild.members:
if not member.bot:
if not pause_role in member.roles:
try:
try:
await member.send(f"|| {res['images'][0]['url']} ||") #waifu.im
except:
await member.send(f"|| {res['url']} ||") #waifu.pics
except:
ch = bot.get_channel(1006267225432408155)
em = discord.Embed(description="I cannot send you your supply, please check your Privacy & Saftey settings.", color=discord.Colour.red())
await ch.send(f"oii senpai!!! {member.mention}", embed=em)
channel = bot.get_channel(1006254993227137188)
log_channel = bot.get_channel(990523749721833532)
txt = await channel.fetch_message(1006506210092122172)
dt = datetime.now()
embed = discord.Embed(description=f"✅ Latest supply sent <t:{int(dt.timestamp())}:R>\n```diff\n+ Successfully sent to everyone! +```")
embed.set_footer(text="Supply interval: 30 mins")
await txt.edit(embed=embed)
await log_channel.send("Supplied successfully!!!")
await asyncio.sleep(1800)
# else:
# await ctx.send("❌ Supply denied!")
@bot.event
async def on_member_join(member):
url = "https://api.waifu.im/random/?" \
"&gif=false" \
"&is_nsfw=true"
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
res = await response.json()
if not member.bot:
try:
await member.send(f"|| {res['images'][0]['url']} || (Wait for your next supply uwu)")
except:
ch = bot.get_channel(1006267225432408155)
em = discord.Embed(description="I cannot send you your supply, please check your Privacy & Saftey settings.", color=discord.Colour.red())
await ch.send(f"oii senpai!!! {member.mention}", embed=em)
@bot.command()
async def pause(ctx):
guild = bot.get_guild(1006254992648327290)
pause_role = guild.get_role(1010788120511381524)
if not pause_role in ctx.message.author.roles:
await ctx.message.author.add_roles(pause_role)
await ctx.message.add_reaction("✅")
await ctx.message.author.send("I have paused your supply! Use command `?unpause` in <#1006267225432408155> to continue supplies")
else:
await ctx.send("I have already paused your supply!\nIf you want to unpause then use the command `?unpause`")
@bot.command()
async def unpause(ctx):
guild = bot.get_guild(1006254992648327290)
pause_role = guild.get_role(1010788120511381524)
if pause_role in ctx.message.author.roles:
await ctx.message.author.remove_roles(pause_role)
await ctx.message.add_reaction('✅')
await ctx.message.author.send("I'll be sending you supplies!")
else:
await ctx.message.add_reaction('✅')
@bot.command()
async def ping(ctx):
await ctx.send('Pong! `{0}ms`'.format(round(bot.latency, 1)))
@bot.event
async def on_command_error(ctx, error):
em = discord.Embed(description=f"Command: `{ctx.command}`\n```{error}```")
await ctx.send(embed=em)
raise error
asyncio.run(main())