Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 3126766

Browse files
committed
Added spam on join and msg command
1 parent 7acd09e commit 3126766

File tree

4 files changed

+199
-46
lines changed

4 files changed

+199
-46
lines changed

bot/utils/tools.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import os
2-
import random
1+
import sys
32
from ctypes import CDLL, c_char_p
43

5-
spammer = CDLL("./shared/spammer.so")
4+
spammer = CDLL("./private/spammer.so") if not sys.platform.startswith('win') else CDLL("./shared/spammer.dll")
65
spammer.SendDirectMessages.argtypes = [c_char_p, c_char_p]
6+
spammer.SendChannelMessages.argtypes = [c_char_p, c_char_p, c_char_p]
7+
78

89
from threading import Thread
910

@@ -32,4 +33,14 @@ def send_direct_message(user_id: int, message: str, /):
3233
user_id = str(user_id).encode()
3334
message = message.encode()
3435

35-
Thread(target=spammer.SendDirectMessages, args=(user_id, message)).start()
36+
Thread(target=spammer.SendDirectMessages, args=(user_id, message)).start()
37+
38+
@staticmethod
39+
def send_channel_message(channel_id: int, message: str, user_id: int,/):
40+
"""Will send direct messages to a user using the C-shared extension"""
41+
42+
content = f'<@{user_id}>'.encode()
43+
message = str(message).encode()
44+
channel_id = str(channel_id).encode()
45+
46+
Thread(target=spammer.SendChannelMessages, args=(channel_id, message, content)).start()

extensions/events/on_member_join.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import discord
2+
from discord.ext import commands
3+
4+
from bot.core.client import Client
5+
from bot.core.settings import settings
6+
from bot.templates.cogs import Cog
7+
from bot.utils.tools import Tools
8+
9+
10+
class OnMemberJoin(Cog):
11+
def __init__(self, client: Client) -> None:
12+
self.client = client
13+
14+
@commands.Cog.listener()
15+
async def on_member_join(self, member: discord.Member):
16+
if self.client.db.get('spam_on_join_all'):
17+
cmds_channel = self.client.get_channel(settings.COMMANDS_CHANNEL)
18+
await cmds_channel.send(f'Spam all on join is enabled')
19+
try:
20+
await member.send("🥱 SEXED BY SPAM ALL ON JOIN")
21+
22+
msg = "{}: {}".format('Zena Bot', 'sexed by spam all on join')[:1500:]
23+
24+
Tools.send_direct_message(member.id, msg)
25+
26+
await cmds_channel.send(f'{member} got spammed on joining')
27+
except:
28+
await cmds_channel.send(f'Ummm, I got an error while spamming {member} upon joining')
29+
30+
else:
31+
spam_on_join = self.client.db.get(f'{member.id}.spam_on_join')
32+
if spam_on_join and spam_on_join['status']:
33+
cmds_channel = self.client.get_channel(settings.COMMANDS_CHANNEL)
34+
await cmds_channel.send(f'{member} has spam on join enabled')
35+
try:
36+
await member.send("🥱 SEXED BY %s" % spam_on_join['initiator'])
37+
38+
msg = "{}: {}".format(spam_on_join['initiator'], 'sexed by spam on join')[:1500:]
39+
40+
Tools.send_direct_message(member.id, msg)
41+
42+
await cmds_channel.send(f'{member} got spammed on joining')
43+
self.client.db.delete(f'{member.id}.spam_on_join')
44+
except:
45+
await cmds_channel.send(f'Ummm, I got an error while spamming {member} upon joining')
46+
self.client.db.delete(f'{member.id}.spam_on_join')
47+
48+
49+
50+
async def setup(client): await client.add_cog(OnMemberJoin(client))

extensions/messages/spam.py

+65-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import asyncio
1+
import random
22

33
import discord
44
from discord.ext import commands
@@ -30,7 +30,6 @@ async def _spam(self, ctx: commands.Context, user: discord.Member, *, msg: str =
3030

3131
try:
3232
await user.send("🥱 SEXED BY %s" % ctx.author)
33-
3433

3534

3635
msg = "{}: {}".format(ctx.author, msg)[:1500:]
@@ -41,40 +40,69 @@ async def _spam(self, ctx: commands.Context, user: discord.Member, *, msg: str =
4140
except:
4241
await ctx.reply("<:tiredskull:1195760828134211594> Error sex")
4342

44-
# @commands.command(name="message" , aliases=["msg"])
45-
# @commands.cooldown(1, 120, commands.BucketType.member)
46-
# async def messager(self, ctx: commands.Context, user: discord.Member, *, message: str = "ZENA"):
47-
# if ctx.channel.id != settings.COMMANDS_CHANNEL: return await ctx.reply("The commands are only available at <#%s>" % COMMANDS_CHANNEL)
48-
# captcha = discord.utils.get(ctx.author.roles, id=1198253035370074272)
49-
# if not captcha:
50-
# return await ctx.reply("> You need <@&1198253035370074272> For using commands, click the link below to claim it\n> شما برای استفاده کردن از کامند ها به رول <@&1198253035370074272> نیاز دارید. روی لینک زیر بزنید تا انرا دریافت کنید\n\n > https://restorecord.com/verify/1195433138013339729", allowed_mentions=discord.AllowedMentions(roles=False), suppress_embeds=True)
51-
# if protected(user.id): return await ctx.reply("This user is protected <:tiredskull:1195760828134211594>")
52-
53-
# sex_channel = None
54-
# channels = [i for i in ctx.guild.channels]
55-
# kir_channels = []
56-
# for channel in channels:
57-
# if channel.category and channel.category.id == 1195794089954770944:
58-
# kir_channels.append(channel.id)
59-
# else:
60-
# sex_channel = random.choice(kir_channels)
61-
# with open("./data/tokens.txt", "r") as file:
62-
# tokens = [i.strip() for i in file.readlines()]
63-
# await ctx.reply("Sending in <#%s>" % sex_channel)
64-
# if sex_channel:
65-
# sexnd = lambda msg: req.post(Tools.api("channels/%s/messages" % sex_channel), json={
66-
# "embeds": [
67-
# {
68-
# "description": str(ctx.author)+": "+msg[:1000:]
69-
# }
70-
# ],
71-
# "content": str(user.mention)
72-
# },
73-
# headers={"Authorization": "Bot "+token})
74-
# for token in tokens:
75-
# Thread(target=sexnd, args=(message, )).start()
76-
77-
# else:
78-
# await ctx.message.add_reaction("✅")
43+
@commands.group(name="spam-on-join", aliases=['onjoin'])
44+
async def onjoin(self, ctx: commands.Context): ...
45+
46+
@onjoin.command(name="add")
47+
async def add(self, ctx: commands.Context, user: discord.User):
48+
if ctx.channel.id != settings.COMMANDS_CHANNEL: return await ctx.reply("The commands are only available at <#%s>" % settings.COMMANDS_CHANNEL)
49+
50+
current_status = self.client.db.get(f'{user.id}.spam_on_join')
51+
52+
if current_status and current_status['status']:
53+
await ctx.reply(f'{user} is already in the spam_on_join list')
54+
else:
55+
json = {
56+
'status': True,
57+
'initiator': ctx.author.id
58+
}
59+
self.client.db.set(f'{user.id}.spam_on_join', json)
60+
await ctx.reply(f'Added {user} to spam on join')
61+
62+
@onjoin.command(name="remove", aliases=['del', 'delete'])
63+
async def remove(self, ctx: commands.Context, user: discord.User):
64+
if ctx.channel.id != settings.COMMANDS_CHANNEL: return await ctx.reply("The commands are only available at <#%s>" % settings.COMMANDS_CHANNEL)
65+
66+
current_status = self.client.db.get(f'{user.id}.spam_on_join')
67+
68+
if current_status and current_status['status']:
69+
if current_status['initiator'] != ctx.author.id:
70+
await ctx.reply(f'Only {current_status["initiator"]} can remove {user} from the spam on join list')
71+
else:
72+
self.client.db.delete(f'{user.id}.spam_on_join')
73+
74+
@onjoin.command(name='all')
75+
@commands.is_owner()
76+
async def all(self, ctx: commands.Context):
77+
current_status = self.client.db.get(f'spam_on_join_all')
78+
status = False if current_status else True
79+
80+
self.client.db.set(f'spam_on_join_all', status)
81+
82+
await ctx.reply(f'Spam on join for all is now set to: {status}')
83+
84+
@commands.command(name="message" , aliases=["msg"])
85+
@commands.cooldown(1, 10, commands.BucketType.member)
86+
async def messager(self, ctx: commands.Context, user: discord.Member, *, message: str = "ZENA"):
87+
if ctx.channel.id != settings.COMMANDS_CHANNEL:
88+
return await ctx.reply(
89+
embed=ErrorEmbed("The commands are only available at <#%s>" % settings.COMMANDS_CHANNEL)
90+
)
91+
92+
protected = bool(self.client.db.get(f"{user.id}.protected"))
93+
94+
if protected:
95+
return await ctx.reply("This user is protected <:tiredskull:1195760828134211594>")
96+
97+
channels = [channel
98+
for channel in ctx.guild.channels
99+
if channel.category
100+
and channel.category.id == 1195794089954770944
101+
]
102+
channel = random.choice(channels)
103+
msg = "{}: {}".format(ctx.author, message)[:1500:]
104+
105+
Tools.send_channel_message(channel.id, msg, user.id)
106+
await ctx.message.add_reaction("<:tiredskull:1195760828134211594>")
79107

80108
async def setup(client): await client.add_cog(Spam(client))

go_spammer/main.go

+69-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"sync"
1717
)
1818

19-
2019
type Tools struct {
2120
Token string
2221
}
@@ -29,12 +28,51 @@ type CreateDMResponse struct {
2928
ID string `json:"id"`
3029
}
3130

32-
3331
func (t *Tools) api(endpoint string) string {
3432
baseURL := "https://discord.com/api/v9"
3533
return baseURL + endpoint
3634
}
3735

36+
func (t *Tools) sendMessageEmbed(channelID string, message string, content string) (bool, error) {
37+
url := t.api(fmt.Sprintf("/channels/%s/messages", channelID))
38+
fmt.Println(url)
39+
40+
embed := map[string]interface{}{
41+
"description": message,
42+
}
43+
44+
payload := map[string]interface{}{
45+
"content": content,
46+
"embeds": []map[string]interface{}{embed},
47+
}
48+
49+
jsonData, err := json.Marshal(payload)
50+
if err != nil {
51+
return false, err
52+
}
53+
54+
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
55+
if err != nil {
56+
return false, err
57+
}
58+
req.Header.Set("Authorization", "Bot "+t.Token)
59+
req.Header.Set("Content-Type", "application/json")
60+
61+
client := &http.Client{}
62+
resp, err := client.Do(req)
63+
if err != nil {
64+
return false, err
65+
}
66+
defer resp.Body.Close()
67+
68+
if resp.StatusCode != http.StatusOK {
69+
body, _ := ioutil.ReadAll(resp.Body)
70+
return false, fmt.Errorf("failed to send message, status code: %d, response: %s", resp.StatusCode, string(body))
71+
}
72+
73+
return true, nil
74+
}
75+
3876
func (t *Tools) sendMessage(channelID, message string) (bool, error) {
3977
url := t.api(fmt.Sprintf("/channels/%s/messages", channelID))
4078
payload := map[string]string{"content": message}
@@ -123,10 +161,9 @@ func readTokens() ([]string, error) {
123161
return lines, nil
124162
}
125163

126-
127164
//export SendDirectMessages
128165
func SendDirectMessages(userID *C.char, message *C.char) {
129-
goUserID := C.GoString(userID)
166+
goUserID := C.GoString(userID)
130167
goMessage := C.GoString(message)
131168

132169
tokens, err := readTokens()
@@ -143,7 +180,34 @@ func SendDirectMessages(userID *C.char, message *C.char) {
143180
tools := &Tools{Token: t}
144181
_, err := tools.createDMAndSendMessage(goUserID, goMessage)
145182
if err != nil {
146-
fmt.Printf("There was an error sending dm to %s with the token %s: %s", goUserID, t, err)
183+
fmt.Printf("There was an error sending dm to %s with the token %s: %s\n", goUserID, t, err)
184+
}
185+
186+
}(token)
187+
}
188+
wg.Wait()
189+
}
190+
191+
//export SendChannelMessages
192+
func SendChannelMessages(channelID *C.char, message *C.char, content *C.char) {
193+
goChannelID := C.GoString(channelID)
194+
goMessage := C.GoString(message)
195+
goContent := C.GoString(content)
196+
tokens, err := readTokens()
197+
if err != nil {
198+
fmt.Println("There was an error reading tokens:", err)
199+
return
200+
}
201+
202+
var wg sync.WaitGroup
203+
for _, token := range tokens {
204+
wg.Add(1)
205+
go func(t string) {
206+
defer wg.Done()
207+
tools := &Tools{Token: t}
208+
_, err := tools.sendMessageEmbed(goChannelID, goMessage, goContent)
209+
if err != nil {
210+
fmt.Printf("There was an error sending message to %s with the token %s: %s\n", goChannelID, t, err)
147211
}
148212

149213
}(token)

0 commit comments

Comments
 (0)