Permalink
Browse files

Merge pull request #355 from lansuite/184-discord-module

184 discord module
  • Loading branch information...
M4LuZ committed Sep 13, 2018
2 parents 0cc34c2 + 8242a12 commit a785ab0c59b213f291f89d9f2c56abde06ae26e8
View
@@ -42,6 +42,7 @@
"LanSuite\\Module\\CashMgr\\": "modules/cashmgr/Classes/",
"LanSuite\\Module\\ClanMgr\\": "modules/clanmgr/Classes/",
"LanSuite\\Module\\Cron2\\": "modules/cron2/Classes/",
"LanSuite\\Module\\Discord\\": "modules/discord/Classes/",
"LanSuite\\Module\\Foodcenter\\": "modules/foodcenter/Classes/",
"LanSuite\\Module\\GuestList\\": "modules/guestlist/Classes/",
"LanSuite\\Module\\Install\\": "modules/install/Classes/",
@@ -219,12 +219,12 @@ public function add_css_code($csscode)
}
/**
* Add Path for CSS-File for implementation in hHeader
* Add Path for a CSS-File to be included in the header output
*
* @param string $csspath
* @return void
*/
private function add_css_path($csspath)
public function add_css_path($csspath)
{
$this->main_header_cssfiles .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$csspath."\" />\n";
}
@@ -0,0 +1,111 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace LanSuite\Module\Discord;
/**
* Class implementation for all functions required to interact with the Discord and LS API
* General intention is to roll this up with the TS3 code into a general "voiceserver" parent class
*
* @author MaLuZ
*/
class Discord {
// Storage for the discord server id
private $discordServerId = 0;
public function __construct($discordServerId = 0){
global $cfg,$func;
//Have a look first, if OpenSSL is enabled as module...
if (extension_loaded('openssl'))
{
//Check if server id was passed via constructor, use configuration value otherwise
if ($discordServerId){
$this->discordServerId = $disordServerId;
} elseif (isset($cfg['discord_server_id'])) {
$this ->discordServerId = $cfg['discord_server_id'];
} else {
$func->error(t('Es wurde keine Discord server ID konfiguriert oder übergeben'));
}
}
else {
$func->error('OpenSSL-Modul nicht geladen!');
}
}
/**
* Retrieves JSON widget data from the Discord server via the public API
* Data is being returned as multi-dimensional array
*
* @return stdClass decoded JSON content as object of stdClass, FALSE on error
*/
public function fetchServerData(){
$APIurl = 'https://discordapp.com/api/servers/'.$this->discordServerId .'/widget.json';
$JsonReturnData = file_get_contents($APIurl);
return json_decode($JsonReturnData, false);
}
/**
* Show discordbox
*
* @author CCG*Centurio
* @version $Id: discord.php 1673 2018-04-04 08:13:47Z CCG*Centurio $
* @return string Box content ready for output
*/
public function genBoxContent($discordServerData){
$boxContent ="<li class='discord_server_name'>{$discordServerData->name}<br>";
// -------------------------------- MEMBERS ---------------------------------------- //
if (count($discordServerData->members) > 0) {
$boxContent .= '<span class="online_users badge green">' . count($discordServerData->members) . '</span>';
}
else {
$boxContent .= '<span class="online_users badge red">' . count($discordServerData->members) . '</span>';
}
$boxContent .= '<ul class="online_sidebar">';
foreach($discordServerData->members as $member){
if (array_key_exists('nick', $member)) {
$boxContent .= '<li><img src="'. $member->avatar_url .'" class="'. $member->status .' discord_avatar">' . $member->nick . '</li>';
}
else {
$boxContent .= '<li><img src="'. $member->avatar_url .'" class="'. $member->status .' discord_avatar">' . $member->username . '</li>';
}
}
$boxContent .= '</ul>';
// -------------------------------- CHANNELS ---------------------------------------- //
if ($discordServerData->channels) {
usort($discordServerData->channels, function($a, $b) {
return ($a->position > $b->position) ? 1 : -1;
});
$boxContent .= '<ul class="online_sidebar_channel">';
foreach ($discordServerData->members as $member) {
if (array_key_exists('nick', $member) && !empty($member->channel_id)) {
$channel_members[$member->channel_id][] = $member->nick;
}
elseif (!empty($member->channel_id)) {
$channel_members[$member->channel_id][] = $member->username;
}
}
foreach ($discordServerData->channels as $channel) {
$boxContent .= "<li class='channel'>{$channel->name}";
if (!empty($channel_members[$channel->id])) {
$boxContent .= '<ul>';
foreach ($channel_members[$channel->id] as $username) {
$boxContent .= "<li class='channel_member'>$username</li>";
}
$boxContent .= '</ul>';
}
$boxContent .= "</li>";
}
}
$boxContent .= "<input class=\"btn-join\" type=button onClick=\"parent.open('". $discordServerData->instant_invite ." ')\" value='Join'>";
$boxContent .= '</ul>';
return $boxContent;
}
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<lansuite>
<box>
<name>Discord</name>
<place>1</place>
<pos>6</pos>
<active>0</active>
<internet>0</internet>
<login>0</login>
<source>discord</source>
<callback></callback>
</box>
</lansuite>
@@ -0,0 +1,132 @@
/* +++++ DISCORD THEMING +++++ */
/* Box User */
.online_sidebar {
height: auto;
overflow: auto;
padding: 10px;
border: 0px solid #131313;
white-space: nowrap;
}
/* Box Channel */
.online_sidebar_channel {
overflow: auto;
padding: 10px;
border: 0px solid #131313;
white-space: nowrap;
}
/* Text Online User Name */
.online_sidebar > li {
margin: 7px 7px 7px 0px;
list-style: none;
text-overflow: ellipsis;
font-size: 12px;
color: rgba(77, 77, 77, 0.85);
}
/* Text Online User Badge */
.online_users {
padding: 10px;
text-align: center;
margin: 0 0 14px 0;
font-size: 10px;
}
.online_users:after { margin-left: 3px; }
html[lang="de"] .online_users:after { content: "Benutzer online"; }
html[lang="en"] .online_users:after { content: "User online"; }
.green {
background: rgba(50, 205, 50, 1); /*lime-green*/
color: #dee2e6;
margin: 5px 5px 5px 5px;
padding: 1px 2px 1px 2px;
border-radius: 5px;
}
.red {
background: rgba(220, 20, 60, 1); /*crimson*/
color: #dee2e6;
margin: 5px 5px 5px 5px;
padding: 1px 2px 1px 2px;
border-radius: 5px;
}
/* User Avatar */
.discord_avatar {
width: 14px;
height: 14px;
border-radius: 50px;
margin-right: 5px;
margin-top: 2px;
}
/* Text Channel Name */
li.channel {
font-size: 11px;
color: rgba(99, 99, 99, 1);
}
/* Text Channel User Name */
li.channel > ul > li.channel_member {
font-weight: normal;
font-size: 9px;
list-style: none;
margin-left: -13px;
color: rgba(99, 99, 99, 1);
}
/* Text Symbol vor Channel User Name */
li.channel > ul > li.channel_member:before {
font-size: 14px;
font-weight: bold;
content: "·";
list-style: none;
color: rgba(99, 99, 99, 0.75);
margin-right: 3px;
}
/* Text Server Name */
.discord_server_name {
font-size: 10px;
font-weight: bold;
list-style: none;
color: #000000;
}
/* User Online-Status */
.online {
border: solid 1px #dee2e6;
box-shadow: 0px 0px 0px 2px #43b581;
}
.idle {
border: solid 2px #dee2e6;
box-shadow: 0px 0px 0px 2px #faa61a;
}
.dnd {
border: solid 2px #dee2e6;
box-shadow: 0px 0px 0px 2px #f04747;
}
/* Join Button (Invite) */
.btn-join {
list-style: none;
cursor: pointer;
color: rgba(167, 181, 129, 1);
font-size: 9px;
font-weight: bold;
margin-top: 20px;
padding-top: 2px;
padding-right: 10px;
padding-bottom: 2px;
padding-left: 10px;
border-radius: 5px;
border: 1px solid #363636;
background: #363636;
outline: none;
position: relative;
transition: 0.6s ease-in-out;
}
.btn-join:hover {
color: #363636;
background: rgba(167, 181, 129, 1);
list-style: none;
transition: 0.6s ease-in-out;
}
@@ -0,0 +1,16 @@
<?php
/**
* Code to trigger Discord box generation and inclusion of the formatting CSS code
*/
$discord = new \LanSuite\Module\Discord\Discord();
$discordServerData = $discord->fetchServerData();
//Load either custom style definition or fall back to default one
if (file_exists('design/' . $auth['design'] . '/discord.css')) {
$framework->add_css_path('design/' . $auth['design'] . '/discord.css');
} else {
$framework->add_css_path('modules/discord/boxes/default.css');
}
$boxcontent = $discord->genBoxContent($discordServerData);
$box->Row($boxcontent);
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<config>
<group>
<head>
<name>Discord Serverkonfiguration</name>
</head>
<items>
<item>
<name>discord_server_id</name>
<type>int</type>
<default>0</default>
<description>Discord server ID</description>
</item>
</items>
</group>
</config>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<lansuite-module>
<name>discord</name> <!-- The modules internal name. This should be the same as the name of its folder! -->
<caption>Discord</caption> <!-- The modulname displayed to the user -->
<description>Integration von Discord as Box</description> <!-- A short description of the module -->
<active>0</active> <!-- Is the module activated by default? 0/1 -->
<changeable>1</changeable> <!-- May the user de-/activate the module? 0/1 -->
<author>MaLuZ</author> <!-- The author of this module -->
<email></email> <!-- The E-Mail-Adress of the modules author -->
<version>0.1</version> <!-- The version of this module -->
<state>in development</state> <!-- The state of this module (f.e.: stable, in development, beta, ...) -->
</lansuite-module>

0 comments on commit a785ab0

Please sign in to comment.