Skip to content

Commit b32614a

Browse files
committed
Initial Release
0 parents  commit b32614a

18 files changed

+1113
-0
lines changed

README.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<p align="center"><a href="https://syntafin.dev" target="_blank"><img src="https://share.syntafin.de/github/dev_slogan.png" width="600" /></a></p>
2+
3+
<p align="center">
4+
<a href="https://discord.gg/7NqGZfn" target="_blank"><img src="https://img.shields.io/discord/616573354685759488?color=fe93db&label=Discord&style=for-the-badge" alt="Discord" /></a>
5+
<a href="xmpp://[email protected]"><img src="https://img.shields.io/static/v1?label=XMPP&[email protected]&color=fe93db&style=for-the-badge" alt="XMPP" /></a>
6+
<a href="mailto://[email protected]"><img src="https://img.shields.io/static/v1?label=Mail&[email protected]&color=fe93db&style=for-the-badge" alt="Email me" /></a>
7+
<a href="LICENSE"><img src="https://img.shields.io/static/v1?label=Lizenz&message=MIT&color=fe93db&style=for-the-badge" alt="License" /></a>
8+
</p>
9+
10+
# Table of contents
11+
12+
* [About the project](#about-the-project)
13+
* [Contributing](#contributing)
14+
* [Versioning](#versioning)
15+
* [Authors](#authors)
16+
* [License](#license)
17+
18+
# About the project
19+
20+
This is a simple package to provide a Discord Widget through a Livewire component.
21+
22+
# Installation
23+
24+
``composer require syntafin/discordwidget``
25+
26+
# Usage
27+
28+
``@livewire('discord-widget', ['serverId' => '1234'])``
29+
30+
# Contributing
31+
32+
There are many ways to help this open source project. Write bug reports, make feature requests, write code, help us translate the page (maybe we will support Chinese and Korean if we have people who help us with). We look forwar to every contribution.
33+
34+
For more information and our guidelines, please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file.
35+
36+
# Versioning
37+
38+
We use [SemVer](http://semver.org/) for versioning. For available versions, see the [tags on this repository](tags).
39+
40+
# Authors
41+
42+
* [Syntafin](https://github.com/syntafin)
43+
44+
# License
45+
46+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
47+
48+
# TODO
49+
50+
* Replace Bootstrap with own
51+
* Get assets published (CSS/SCSS)

composer.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "syntafin/discordwidget",
3+
"description": "A Discord Widget for Laravel/Livewire",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Syntafin\\DiscordWidget\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "Syntafin",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"minimum-stability": "stable",
18+
"require": {
19+
"php": ">=7.4",
20+
"laravel/framework": "^8.0"
21+
},
22+
"extra": {
23+
"laravel": {
24+
"providers": [
25+
"Syntafin\\DiscordWidget\\DiscordWidgetServiceProvider"
26+
]
27+
}
28+
}
29+
}

src/Components/Widget.php

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace Syntafin\DiscordWidget\Components;
4+
5+
use Livewire\Component;
6+
use Illuminate\Support\Facades\Http;
7+
8+
class Widget extends Component
9+
{
10+
public $serverId;
11+
12+
public function mount($serverId)
13+
{
14+
$this->serverId = $serverId;
15+
}
16+
17+
public function render()
18+
{
19+
return view('discord-widget::widget', [
20+
'data' => $this->getServer($this->serverId)
21+
]);
22+
}
23+
24+
private function getServer($serverId)
25+
{
26+
$result = Http::get('https://discordapp.com/api/guilds/'.$serverId.'/widget.json');
27+
$response = json_decode($result->getBody());
28+
29+
if(isset($response->message)) {
30+
$widgetdata = (object) [
31+
'error' => $response->message,
32+
'code' => $response->code
33+
];
34+
35+
return $widgetdata;
36+
}
37+
38+
foreach($response->members as $i => $member) {
39+
if(!empty($member->channel_id)) {
40+
$channelMembers[$member->channel_id][] = $member;
41+
}
42+
}
43+
44+
if(!empty($response->channels)) {
45+
usort($response->channels, static function($a, $b) {
46+
if($a->position === $b->position) {
47+
return 0;
48+
}
49+
50+
return $a->position < $b->position ? -1 : 1;
51+
});
52+
}
53+
54+
if(isset($channelMembers))
55+
{
56+
$widgetdata = (object) [
57+
'channel_list' => $response->channels,
58+
'member_list' => $response->members,
59+
'channel_count' => count($response->channels),
60+
'member_count' => count($response->members),
61+
'server_name' => $response->name,
62+
'instant_invite' => $response->instant_invite,
63+
'channelMembers' => $channelMembers
64+
];
65+
}else{
66+
$widgetdata = (object) [
67+
'channel_list' => $response->channels,
68+
'member_list' => $response->members,
69+
'channel_count' => count($response->channels),
70+
'member_count' => count($response->members),
71+
'server_name' => $response->name,
72+
'instant_invite' => $response->instant_invite
73+
];
74+
}
75+
76+
return $widgetdata;
77+
}
78+
}

src/DiscordWidgetServiceProvider.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Syntafin\DiscordWidget;
4+
5+
use Syntafin\DiscordWidget\Components\Widget;
6+
use Illuminate\Support\ServiceProvider;
7+
use Livewire\Livewire;
8+
9+
class DiscordWidgetServiceProvider extends ServiceProvider {
10+
public function boot() {
11+
Livewire::component('discord-widget', Widget::class);
12+
13+
$this->loadViewsFrom(__DIR__.'/views', 'discord-widget');
14+
$this->loadTranslationsFrom(__DIR__.'/lang', 'discord-widget');
15+
$this->mergeConfigFrom(__DIR__.'/config.php', 'discord-widget');
16+
}
17+
}

src/config.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'avatar' => env('DISCORD_AVATAR', true)
5+
];

src/css/widget.css

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
.syntafinDiscordWidget {
2+
max-height: 500px;
3+
overflow: auto;
4+
padding-right: 5px;
5+
position: relative;
6+
}
7+
.syntafinDiscordWidget > div:not(:first-child) {
8+
margin-top: 10px;
9+
}
10+
.syntafinDiscordWidget .discordWidgetUsers > .sidebarItemList, .syntafinDiscordWidget .discordWidgetChannels > .sidebarItemList {
11+
margin-left: 5px;
12+
}
13+
.syntafinDiscordWidget .listTitle {
14+
margin-bottom: 10px;
15+
}
16+
.syntafinDiscordWidget .syntafinDiscordWidgetChannels li:not(.discordChannel) {
17+
margin-left: 0px;
18+
}
19+
.syntafinDiscordWidget .widget-member {
20+
-ms-flex-align: center;
21+
-webkit-box-align: center;
22+
align-items: center;
23+
display: -webkit-box;
24+
display: -ms-flexbox;
25+
display: flex;
26+
margin: 6px 0;
27+
}
28+
.syntafinDiscordWidget .widget-member .widget-member-name {
29+
-ms-flex: 1;
30+
-webkit-box-flex: 1;
31+
flex: 1;
32+
overflow: hidden;
33+
text-overflow: ellipsis;
34+
white-space: nowrap;
35+
}
36+
.syntafinDiscordWidget .widget-member:not([data-discord-user-status="online"]) .widget-member-name {
37+
opacity: 0.7;
38+
}
39+
.syntafinDiscordWidget .widget-member .widget-member-game {
40+
-ms-flex: 1;
41+
-webkit-box-flex: 1;
42+
flex: 1;
43+
overflow: hidden;
44+
text-align: right;
45+
text-overflow: ellipsis;
46+
white-space: nowrap;
47+
}
48+
.syntafinDiscordWidget .widget-member .widget-member-avatar {
49+
height: 16px;
50+
margin-right: 4px;
51+
position: relative;
52+
width: 16px;
53+
}
54+
.syntafinDiscordWidget .widget-member .widget-member-avatar img {
55+
border-radius: 8px;
56+
height: 16px;
57+
width: 16px;
58+
vertical-align: initial;
59+
}
60+
.syntafinDiscordWidget .widget-member .widget-member-status:not(.noAvatar) {
61+
border-radius: 3px;
62+
bottom: 0;
63+
height: 6px;
64+
position: absolute;
65+
right: 0;
66+
width: 6px;
67+
vertical-align: initial;
68+
}
69+
.syntafinDiscordWidget .widget-member .widget-member-status.noAvatar {
70+
border-radius: 8px;
71+
height: 16px;
72+
width: 16px;
73+
margin-right: 4px;
74+
position: relative;
75+
display: block;
76+
}
77+
.syntafinDiscordWidget .widget-member .widget-member-status.widget-member-status-online {
78+
background-color: #43b581;
79+
}
80+
.syntafinDiscordWidget .widget-member .widget-member-status.widget-member-status-idle {
81+
background-color: #faa61a;
82+
}
83+
.syntafinDiscordWidget .widget-member .widget-member-status.widget-member-status-offline {
84+
background-color: #747f8d;
85+
}
86+
.syntafinDiscordWidget .widget-member .widget-member-status.widget-member-status-dnd {
87+
background-color: #f04747;
88+
}
89+
.syntafinDiscordWidget .widget-icon {
90+
flex: none;
91+
background-color: transparent;
92+
background-size: 16px 16px;
93+
display: inline-block;
94+
height: 16px;
95+
width: 16px;
96+
}
97+
.syntafinDiscordWidget .widget-icon + .widget-icon {
98+
margin-left: 8px;
99+
}
100+
.syntafinDiscordWidget .widget-icon.widget-icon-mute:before {
101+
content: "\f131";
102+
}
103+
.syntafinDiscordWidget .widget-icon.widget-icon-deaf:before {
104+
content: "\f2a4";
105+
}

src/lang/de/widget.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'voicechannel' => 'Sprachkanäle',
5+
'membersOnline' => 'Mitglieder Online',
6+
'invite' => 'Server beitreten',
7+
'error' => 'Es ist ein Fehler aufgetreten:<br><b>:error</b><br><br>Code: <i>:code</i>'
8+
];

src/lang/en/widget.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'voicechannel' => 'Voice Channel',
5+
'membersOnline' => 'Members Online',
6+
'invite' => 'Join Server',
7+
'error' => 'There is an problem:<br><b>:error</b><br><br>Code: <i>:code</i>'
8+
];

0 commit comments

Comments
 (0)