Add modules for Discord
This commit is contained in:
parent
5d692b9b45
commit
16132c92a9
2 changed files with 34 additions and 0 deletions
20
Scripts/Read-DiscordMessages.psm1
Normal file
20
Scripts/Read-DiscordMessages.psm1
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
function Read-DiscordMessages {
|
||||
param (
|
||||
$Token,
|
||||
$Channel,
|
||||
[switch]$Last
|
||||
)
|
||||
$URL = "https://discordapp.com/api/channels/$Channel/messages"
|
||||
$Output = curl -s -X GET $URL -H "Authorization: Bot $Token" -H "Content-Type: application/json" | ConvertFrom-Json
|
||||
if ($last) {
|
||||
$Output[0].content
|
||||
}
|
||||
else {
|
||||
$Output | Select-Object @{Name="Time"; Expression={$_.timestamp}},
|
||||
@{Name="Message"; Expression={$_.content}},
|
||||
@{Name="UserName"; Expression={$_.author.username}}
|
||||
}
|
||||
}
|
||||
|
||||
# Read-DiscordMessages -Token $DISCORD_TOKEN -Channel $DISCORD_CHANNEL_ID
|
||||
# Read-DiscordMessages -Token $DISCORD_TOKEN -Channel $DISCORD_CHANNEL_ID -Last
|
||||
14
Scripts/Send-DiscordChannel.psm1
Normal file
14
Scripts/Send-DiscordChannel.psm1
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function Send-DiscordChannel {
|
||||
param (
|
||||
$Token,
|
||||
$Channel,
|
||||
$Text
|
||||
)
|
||||
$URL = "https://discordapp.com/api/channels/$Channel/messages"
|
||||
$Body = @{
|
||||
content = $Text
|
||||
} | ConvertTo-Json
|
||||
curl -s $URL -X POST -H "Authorization: Bot $Token" -H "Content-Type: application/json" -d $Body
|
||||
}
|
||||
|
||||
# Send-DiscordChannel -Token $DISCORD_TOKEN -Channel $DISCORD_CHANNEL_ID -Text "Test message from PowerShell"
|
||||
Loading…
Add table
Add a link
Reference in a new issue