Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,39 @@ Please note:
## [FZFalzar's BetterWhisper plugin](https://github.com/FZFalzar/StarryPy_plugins/tree/brutus_whisper/plugins/brutus_whisper)
> Brings better functionality for the sending of Private Messages in Starbound
> Adds the following commands and abilities to the server:
> ```
>```
@permissions(UserLevels.GUEST)
/w <name> <message> #Sends a PM to target. Overrides default /w functionality. alias is /whisper
/r <message> #Replies to the last person who you received a PM from

@permissions(UserLevels.ADMIN)
/socialspy <on|true|off|false> #Enables/Disables SocialSpy, a feature for admins to receive PMs sent by anyone, for policing purposes
> ```
>```

## [FZFalzar's ServerAds plugin](https://github.com/FZFalzar/StarryPy_plugins/tree/serverads_plugin/plugins/serverads_plugin)
> Broadcasts defined messages(ServerAds) at a preset duration
> Additional messages can be specified in config.json under "serverads_list". The plugin prefix can also be modified to your liking, under "serverads_prefix"
> Adds the following commands and abilities to the server:
>```
@permissions(UserLevels.ADMIN)
/ads_reload #Reloads the configuration. Currently does not work as there is no way to reload config.json
/ads_interval [num] #Displays the current interval for message broadcast. If num (in seconds) is specified, the new interval for message broadcast will be set.
>```
### Add the following block to your config file:

>```
"serverads_plugin": {
"auto_activate": true,
"serverads_interval": 30,
"serverads_list": [
"Welcome to the server!",
"Have a nice stay!",
"Have fun, don't grief!",
"Check out our site at somewebpage.com!"
],
"serverads_prefix": "^#FF6600;[SA]"
}
>```

## [Maffi's uptime plugin](https://github.com/MrMarvin/StarryPy_plugins/blob/master/plugins/uptime)
> Very simple plugin that responds to /uptime with the time StarryPy is running.
Expand Down
1 change: 1 addition & 0 deletions plugins/serverads_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from serverads_plugin import ServerAds
129 changes: 129 additions & 0 deletions plugins/serverads_plugin/serverads_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#===========================================================
# ServerAds Plugin
# Author: FZFalzar/Duck of Brutus.SG Starbound (http://steamcommunity.com/groups/BrutusSG)
# Version: v0.1
# Description: Broadcasts defined messages(ServerAds) at a preset duration
#===========================================================

import random
from base_plugin import SimpleCommandPlugin
from plugins.core.player_manager import permissions, UserLevels
from threading import Timer

class ServerAds(SimpleCommandPlugin):
"""
Broadcasts pre-defined messages at set intervals to all players
"""
name = "serverads_plugin"
depends = ["command_dispatcher"]
commands = ["ads_reload", "ads_interval"]
auto_activate = True

def activate(self):
super(ServerAds, self).activate()
self.load_config()
self.ads_thread = None
self.prevMsgIdx = 0
self.rNum = 0
self.start_broadcasting()

def load_config(self):
try:
self.serverads_list = self.config.plugin_config["serverads_list"]
self.serverads_prefix = self.config.plugin_config["serverads_prefix"]
self.interval = self.config.plugin_config["serverads_interval"]
except Exception as e:
self.logger.info("Error occured! %s" % e)
if self.protocol is not None:
self.protocol.send_chat_message("Reload failed! Please check config.json! Then do /ads_reload")
self.protocol.send_chat_message("Initiating with default values...")
self.serverads_list = ["Welcome to the server!", "Have a nice stay!"]
self.serverads_prefix = "[SA]"
self.interval = 30
def save_config(self):
self.config.plugin_config['serverads_list'] = self.serverads_list
self.config.plugin_config['serverads_prefix'] = self.serverads_prefix
self.config.plugin_config['serverads_interval'] = self.interval
self.config.save()

def start_broadcasting(self):
if self.ads_thread is not None:
self.ads_thread.stop()
self.logger.info("Broadcast thread stopped!")
del self.ads_thread
self.ads_thread = ThreadedTimer(self.interval, self.broadcast)
self.ads_thread.start()
self.logger.info("Broadcast thread started!")

def broadcast(self):
#make sure we do not re-broadcast the last message, for variety
if len(self.serverads_list) > 1:
while self.rNum == self.prevMsgIdx:
#randomly pick from the array
self.rNum = random.randint(0, len(self.serverads_list) - 1)
#override previous index
self.prevMsgIdx = self.rNum
self.logger.info("%s %s" % (self.serverads_prefix, self.serverads_list[self.rNum]))
self.factory.broadcast("%s ^#00FF00;%s" % (self.serverads_prefix, self.serverads_list[self.rNum]), 0, "", "ServerAds")
elif len(self.serverads_list) <= 1:
self.logger.info("%s %s" % (self.serverads_prefix, self.serverads_list[0]))
self.factory.broadcast("%s ^#00FF00;%s" % (self.serverads_prefix, self.serverads_list[0]), 0, "", "ServerAds")

@permissions(UserLevels.ADMIN)
def ads_reload(self, data):
"""Reloads values from configuration. Syntax: /ads_reload"""
self.protocol.send_chat_message("ServerAds reloading!")
self.load_config()
self.start_broadcasting()
self.protocol.send_chat_message("ServerAds reloaded!")
self.protocol.send_chat_message("A restart is necessary as there is currently no other way to reload config.json. Sorry for the inconvenience!")

@permissions(UserLevels.ADMIN)
def ads_interval(self, data):
"""Sets interval for display of serverads. Syntax: /ads_interval [duration in seconds]"""
if len(data) == 0:
self.protocol.send_chat_message(self.ads_interval.__doc__)
self.protocol.send_chat_message("Current interval: %s seconds" % self.interval)
return
num = data[0]
try:
self.interval = int(num)
self.protocol.send_chat_message("Interval set -> %s seconds" % self.interval)
except:
self.protocol.send_chat_message("Invalid input! %s" % num)
self.protocol.send_chat_message(self.ads_interval.__doc__)
return

self.save_config()
self.load_config()
self.start_broadcasting()


class ThreadedTimer(object):
#original source, stackoverflow
"""
Provides an interface for an interruptible timer thread
"""
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()

def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)

def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True

def stop(self):
self._timer.cancel()
self.is_running = False