Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SL-Projects Bot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sofiane Lasri
SL-Projects Bot
Commits
aef5afc7
Commit
aef5afc7
authored
3 years ago
by
Sofiane Lasri
Browse files
Options
Downloads
Patches
Plain Diff
envoie des messages du tchat mc
parent
319cd6a6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
index.js
+71
-24
71 additions, 24 deletions
index.js
with
71 additions
and
24 deletions
index.js
+
71
−
24
View file @
aef5afc7
...
@@ -238,38 +238,16 @@ recursiveAsyncReadLine(); //we have to actually start our recursion somehow
...
@@ -238,38 +238,16 @@ recursiveAsyncReadLine(); //we have to actually start our recursion somehow
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////////
app
.
get
(
'
/ping
'
,
(
req
,
res
)
=>
{
res
.
send
(
"
Pong!
"
)
})
app
.
get
(
'
/channels/:id
'
,
(
req
,
res
)
=>
{
var
id
=
req
.
params
.
id
;
res
.
send
(
client
.
channels
.
cache
.
get
(
id
));
})
app
.
get
(
'
/mc/chat/:detail
'
,
(
req
,
res
)
=>
{
var
detail
=
JSON
.
parse
(
decodeURI
(
req
.
params
.
detail
));
res
.
send
(
detail
.
test
);
})
app
.
listen
(
27001
,
()
=>
{
console
.
log
(
'
[
'
+
'
INFO
'
.
yellow
+
'
] Écoute sur
'
.
brightWhite
+
'
node.sl-projects.com:27001
'
.
yellow
);
});
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
// BOT DISCORD
// BOT DISCORD
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
// require the needed discord.js classes
// require the needed discord.js classes
const
{
Client
,
Intents
,
MessageActionRow
,
MessageButton
}
=
require
(
'
discord.js
'
);
const
{
Client
,
Intents
,
MessageActionRow
,
MessageButton
}
=
require
(
'
discord.js
'
);
const
{
verify
}
=
require
(
'
crypto
'
);
// create a new Discord client
// create a new Discord client
const
client
=
new
Client
({
intents
:
[
"
GUILDS
"
,
"
GUILD_MESSAGES
"
,
"
DIRECT_MESSAGES
"
,
"
GUILD_MEMBERS
"
]
});
const
client
=
new
Client
({
intents
:
[
"
GUILDS
"
,
"
GUILD_MESSAGES
"
,
"
DIRECT_MESSAGES
"
,
"
GUILD_MEMBERS
"
]
});
var
mcChatWebhook
;
client
.
on
(
"
ready
"
,
async
function
()
{
client
.
on
(
"
ready
"
,
async
function
()
{
console
.
log
(
'
\n
'
+
"
SL-Projects Bot
"
.
brightCyan
);
console
.
log
(
'
\n
'
+
"
SL-Projects Bot
"
.
brightCyan
);
...
@@ -282,6 +260,8 @@ client.on("ready", async function () {
...
@@ -282,6 +260,8 @@ client.on("ready", async function () {
client
.
user
.
setActivity
(
"
Regarde
"
+
memberCount
+
"
membres
"
);
client
.
user
.
setActivity
(
"
Regarde
"
+
memberCount
+
"
membres
"
);
checkAnniv
();
checkAnniv
();
verifyMcChatWebhook
();
});
});
// Actions lorsqu'un membre rejoins ou part
// Actions lorsqu'un membre rejoins ou part
...
@@ -473,7 +453,50 @@ async function checkAnniv() {
...
@@ -473,7 +453,50 @@ async function checkAnniv() {
}
}
}
}
}
}
}
function
verifyMcChatWebhook
(){
let
mcChatWebhookId
=
botSettings
.
findOne
({
where
:
{
name
:
"
mcChatWebhookId
"
}
});
if
(
mcChatWebhookId
){
console
.
log
(
"
['
"
+
'
INFO
'
.
yellow
+
"
] Le Webhook du serveur MC est déjà configuré.
"
);
let
mcChatWebhookToken
=
botSettings
.
findOne
({
where
:
{
name
:
"
mcChatWebhookToken
"
}
});
if
(
mcChatWebhookToken
){
mcChatWebhook
=
new
Discord
.
WebhookClient
(
mcChatWebhookId
.
value
,
mcChatWebhookToken
.
value
);
}
else
{
console
.
log
(
"
['
"
+
'
ERREUR
'
.
brightRed
+
"
] Impossible de trouver le token du webhook dans la base de donnée.
"
);
createMcChatWebhook
();
}
}
else
{
createMcChatWebhook
();
}
}
function
createMcChatWebhook
(){
console
.
log
(
"
['
"
+
'
INFO
'
.
yellow
+
"
] Création du Webhook du serveur MC.
"
);
client
.
channels
.
cache
.
get
(
config
.
get
(
"
CANAL_CHAT_MC
"
)).
createWebhook
(
'
Chat Serveur Minecraft
'
,
{
avatar
:
'
https://sl-craft.fr/data/images/logo/short-color.png
'
,
})
.
then
(
webhook
=>
{
botSettings
.
create
({
name
:
"
mcChatWebhookId
"
,
value
:
webhook
.
id
});
botSettings
.
create
({
name
:
"
mcChatWebhookToken
"
,
value
:
webhook
.
token
});
mcChatWebhook
=
new
Discord
.
WebhookClient
(
webhook
.
id
,
webhook
.
token
);
console
.
log
(
"
['
"
+
'
INFO
'
.
yellow
+
"
] Le Webhook du serveur MC a été configuré avec succès.
"
);
})
.
catch
(
console
.
error
);
}
function
sendMessageFromMcChat
(
username
,
message
){
webhookClient
.
send
({
content
:
message
,
username
:
username
,
avatarURL
:
'
https://live.mc.sl-projects.com/tiles/faces/32x32/
'
+
username
+
'
.png
'
,
});
}
}
...
@@ -485,3 +508,27 @@ const job = schedule.scheduleJob('0 0 * * *', function(){
...
@@ -485,3 +508,27 @@ const job = schedule.scheduleJob('0 0 * * *', function(){
// login to Discord with your app's token
// login to Discord with your app's token
client
.
login
(
config
.
get
(
"
DISCORD_BOT_TOKEN
"
));
client
.
login
(
config
.
get
(
"
DISCORD_BOT_TOKEN
"
));
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////////
app
.
get
(
'
/ping
'
,
(
req
,
res
)
=>
{
res
.
send
(
"
Pong!
"
)
})
app
.
get
(
'
/channels/:id
'
,
(
req
,
res
)
=>
{
var
id
=
req
.
params
.
id
;
res
.
send
(
client
.
channels
.
cache
.
get
(
id
));
})
app
.
get
(
'
/mc/chat/:detail
'
,
(
req
,
res
)
=>
{
var
detail
=
JSON
.
parse
(
decodeURI
(
req
.
params
.
detail
));
sendMessageFromMcChat
(
detail
.
username
,
detail
.
message
);
})
app
.
listen
(
27001
,
()
=>
{
console
.
log
(
'
[
'
+
'
INFO
'
.
yellow
+
'
] Écoute sur
'
.
brightWhite
+
'
node.sl-projects.com:27001
'
.
yellow
);
});
////////////////////////////////////////////////////////////////
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment