-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
225 lines (194 loc) · 6.21 KB
/
index.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
require("dotenv").config();
const {
Client,
Intents,
Discord,
Message,
RichEmbed,
MessageEmbed,
} = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
const fetch = require("node-fetch");
const { Octokit } = require("octokit");
const octokit = new Octokit({
auth: process.env.GIT_TOKEN,
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
function RandomColorPicker() {
const randomColor = Math.floor(Math.random() * 16777215).toString(16);
return "#" + randomColor;
}
function embedERROR() {
let embed = new MessageEmbed();
embed.setTitle("Something went wronge");
embed.setColor("#ff0000");
return embed;
}
client.on("message", (msg) => {
if (msg.author.bot) return;
//If Bot reply's don't read message
else if (msg.content === "$NOX") {
async function username() {
//To get Master user
const response = await octokit.request("GET /user");
await msg.channel.send(response.data.login);
}
username().catch((res) => {
//Call Function
const embed = embedERROR();
msg.reply({ embeds: [embed] });
});
}
const roleName = msg.member.roles.cache.find((r) => r.name === "Master"); //Assign your custom role name how can use the syntex
if (msg.content.includes("nox") && roleName != null) {
//if it has master syntex
if (msg.content.includes("-l") && msg.content.split(" ").length - 1 == 2) {
// for if it has -l
const content = msg.content.split(" ");
const Listrepo = async () => {
const res = await octokit.request("GET /users/{username}/repos", {
username: content[2],
});
let str = "";
for (let i = 0; i < res.data.length; i++) {
str = str + res.data[i].name + "," + `\n`;
}
const embed = await new MessageEmbed();
embed.setTitle("The repo's are:");
embed.setColor(RandomColorPicker());
// embed.setAuthor( client.user.username , client.user.displayAvatarURL() )
embed.setDescription(str);
return embed;
};
Listrepo()
.then((embed) => {
msg.reply({ embeds: [embed] });
})
.catch((res) => {
if (res.status == 404) {
const embed = embedERROR();
embed.setDescription("User not found");
msg.reply({ embeds: [embed] });
} else {
const embed = embedERROR();
msg.reply({ embeds: [embed] });
}
});
}
else if ( msg.content.includes("-b") && msg.content.split(" ").length - 1 == 3) { // to get the branches of repo of any user
const content = msg.content.split(" ");
const DisplayBranches = async () => {
const res = await octokit.request(
"GET /repos/{owner}/{repo}/branches",
{
owner: content[2],
repo: content[3],
}
);
let str = "";
for (let i = 0; i < res.data.length; i++) {
str = str + res.data[i].name + "," + `\n`;
}
let embed = await new MessageEmbed();
embed.setTitle("The branches are:");
embed.setColor(RandomColorPicker());
embed.setAuthor(client.user.username, client.user.displayAvatarURL());
embed.setDescription(str);
return embed;
}
DisplayBranches()
.then((embed) => {
msg.reply({ embeds: [embed] });
})
.catch((res) => {
if (res.status == 404) {
const embed = embedERROR();
embed.setDescription("Repo not found");
msg.reply({ embeds: [embed] });
} else {
const embed = embedERROR();
msg.reply({ embeds: [embed] });
}
});
}
else if ( msg.content.includes("-p") && msg.content.split(" ").length - 1 == 2 ) { // to display profile card of user
const content = msg.content.split(" ");
const ProfileCard = async () => {
const res = await octokit.request("GET /users/{username}", {
username: content[2],
});
const exampleEmbed = await new MessageEmbed();
if (res.data.name != null) {
exampleEmbed.setTitle(res.data.name);
}
exampleEmbed.setColor(RandomColorPicker());
if (res.data.bio != null)
exampleEmbed.setDescription(res.data.login + "\n" + res.data.bio);
else {
exampleEmbed.setDescription(res.data.login);
}
if (res.data.email != null) {
exampleEmbed.addFields({
name: "Email",
value: res.data.email,
});
}
exampleEmbed.setThumbnail(res.data.avatar_url);
exampleEmbed.addFields({
name: "Link to profile",
value: res.data.html_url,
});
if (res.data.blog != "") {
exampleEmbed.addFields({
name: "Link to Project",
value: res.data.blog,
});
}
if (res.data.twitter_username != null) {
exampleEmbed.addFields({
name: "Twitter",
value: res.data.twitter_username,
});
}
exampleEmbed.addFields(
{
name: "Followers",
value: res.data.followers.toString(),
inline: true,
},
{
name: "Following",
value: res.data.following.toString(),
inline: true,
},
{
name: "Public repo",
value: res.data.public_repos.toString(),
inline: true,
}
);
exampleEmbed.setTimestamp();
return exampleEmbed;
}
ProfileCard()
.then((embed) => {
msg.reply({ embeds: [embed] });
})
.catch((res) => {
if (res.status == 404) {
const embed = embedERROR();
embed.setDescription("User not found");
msg.reply({ embeds: [embed] });
} else {
const embed = embedERROR();
msg.reply({ embeds: [embed] });
}
});
}
}
});
client.login(process.env.Discord_token);