-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.js
146 lines (140 loc) · 6.17 KB
/
global.js
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
const Discord = require("discord.js")
const client = new Discord.Client()
const fs = require("fs")
const prefix = "k!"
const Keyv = require("keyv")
const gmutes = new Keyv("sqlite://gmutes.sqlite", {table: "gmutes"})
client.on("ready", () => {
console.log(client.user.tag + "でログイン中")
});
client.on("message", async message => {
if (message.author.bot) {
return;
}
if (message.channel.type == "dm") {
return;
}
if (message.content == prefix+"global_setup") {
if (!message.channel.permissionsFor(message.guild.me).has("MANAGE_WEBHOOKS")) {
message.channel.send("Webhookを作成する権限がありません。\nMANAGE_WEBHOOKS")
return;
}
message.channel.createWebhook('きのこグローバルチャット用webhook').then(webhook => {
var webhookinfo = {
"id": webhook.id,
"token": webhook.token,
"channel": message.channel.id
}
var savedata = JSON.stringify(webhookinfo);
try {
fs.mkdirSync(`globalchatfiles/${message.guild.id}/`, { recursive: true });
fs.writeFileSync(`globalchatfiles/${message.guild.id}/webhook.json`, savedata);
//成功すれば、Webhookが保存されます。
}
catch (error) {
message.channel.send("<:kiken:812497914168475678>参加できませんでした。\n<:chui:812497940753023017>エラー内容はサーバーに送信されます。" + error)
return;
}
var sentchannelid = webhook.channel
const webhooks = new Discord.WebhookClient(webhook.id, webhook.token)
webhooks.send("<:join:805306364406530049>グローバルチャットに参加しました。\nグローバルチャットルール記載鯖=>https://discord.gg/8eAQ2gP")
//ほかのサーバーに参加通知を送る
//サーバーごとにファイルを読み込んで、webhookで送信する。
client.guilds.cache.forEach(guild => {
try {
var webhookjoined = JSON.parse(fs.readFileSync(`globalchatfiles/${guild.id}/webhook.json`))
} catch (err) {
return;
//参加していなければ、そのサーバーはパスする。
}
var channelid = webhookjoined.channel
try {
client.channels.cache.get(channelid).id
}
catch (error) {
return;
//チャンネルが削除されていたら、動作をキャンセルするコード。
}
var webhookid = webhookjoined.id
var webhooktoken = webhookjoined.token
if (message.channel.id == sentchannelid) return;
if (message.guild.id == guild.id) return;
try {
new Discord.WebhookClient(webhookid, webhooktoken).send("<:join:805306364406530049>" + message.guild.name + "が、グローバルチャットに参加しました。いっぱい雑談しましょう!!", { username: "きのこグローバル全体チャット", disableMentions: "all"})
} catch (error) {
}
})
//webhookは、チャンネルごとに10個までしか作れないので、作成できなかった場合には、参加成功メッセージが来ない仕組み。
}).catch(console.error);
}
if(command === "gmute"){
if(message.author.id === "695500134179536907||663196515384295425") return message.channel.send("あなたはBOT管理者ではありません");
const [a, c] = args
const b = await message.channel.send("Gmuteの準備をしています...")
const gmute = (await gmutes.get(a)) || { score: 0, reason: 0 }
const muteuser = client.users.fetch(a).tag
gmutes.set(a, { score: 1, reason: c })
if (gmute.score == 1) b.edit(`${muteuser}(${message.author.id})をGmuteしました。\n追加理由: ${c}`);
}
if (command === "ungmute") {
if (message.author.id === "695500134179536907||663196515384295425") return message.channel.send("あなたはBOT管理者ではありません");
const [a, c] = args
const b = await message.channel.send("Gmute解除の準備をしています...")
const gmute = (await gmutes.get(a)) || { score: 0, reason: 0 }
const muteuser = client.users.fetch(a).tag
gmutes.set(a, { score: 0, reason: c })
if (gmute.score == 0) b.edit(`${muteuser}(${message.author.id})のGmuteを解除しました。\n解除理由: ${c}`);
}
});
client.on("message", message => {
if (message.author.bot) {
return;
}
if (message.channel.type == "dm") {
return;
}
try {
const guild_webhook = JSON.parse(fs.readFileSync(`globalchatfiles/${message.guild.id}/webhook.json`))
var sentchannelid = guild_webhook.channel
} catch (error) {
return;
//読み取れなかった場合、ほとんどの場合は参加していないのでリターンする。
}
if (message.channel.id == sentchannelid) {
//サーバーごとにファイルを読み込んで、webhookで送信する。
client.guilds.cache.forEach(guild => {
try {
var webhook = JSON.parse(fs.readFileSync(`globalchatfiles/${guild.id}/webhook.json`))
} catch (err) {
return;
//参加していなければ、そのサーバーはパスする。
}
var channelid = webhook.channel
try {
client.channels.cache.get(channelid).id
}
catch (error) {
return;
//チャンネルが削除されていたら、動作をキャンセルするコード。
}
var webhookid = webhook.id
var webhooktoken = webhook.token
var admin = "";
if (message.author.id === "695500134179536907") {
admin = "👑";
}
var check = "";
if (message.author.id === "695500134179536907") {
check = "✅";
}
const serverwebhook = new Discord.WebhookClient(webhookid, webhooktoken)
if (message.channel.id == channelid) return;
if (message.guild.id == guild.id) return;
try {
serverwebhook.send(message.content, { username: message.author.tag + "(" + message.author.id + ") | " + message.guild.name + "(" + message.guild.id + ")" + "(" + admin + check + ")", avatarURL: `https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.png`, disableMentions: "all"})
} catch (error) {
}
})
}
});
client.login("")