corrects some issues with the new adverts service
This commit is contained in:
parent
ff3ee7b443
commit
83c5ae98b1
7 changed files with 101 additions and 12 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
using BetterSecondBot;
|
using BetterSecondBot;
|
||||||
using BetterSecondBotShared.IO;
|
using BetterSecondBotShared.IO;
|
||||||
using BetterSecondBotShared.Json;
|
using BetterSecondBotShared.Json;
|
||||||
|
using BetterSecondBotShared.logs;
|
||||||
using BetterSecondBotShared.Static;
|
using BetterSecondBotShared.Static;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
|
|
@ -17,6 +18,7 @@ namespace BetterSecondbot.Adverts
|
||||||
public advertsService(Cli Master, bool LoadFromDocker)
|
public advertsService(Cli Master, bool LoadFromDocker)
|
||||||
{
|
{
|
||||||
controler = Master;
|
controler = Master;
|
||||||
|
LogFormater.Info("Starting adverts service", true);
|
||||||
if (LoadFromDocker == true)
|
if (LoadFromDocker == true)
|
||||||
{
|
{
|
||||||
loadFromDockerEnv();
|
loadFromDockerEnv();
|
||||||
|
|
@ -29,6 +31,7 @@ namespace BetterSecondbot.Adverts
|
||||||
|
|
||||||
protected void loadFromDisk()
|
protected void loadFromDisk()
|
||||||
{
|
{
|
||||||
|
LogFormater.Info("Loading adverts from Disk", true);
|
||||||
advertsBlob loadedAdverts = new advertsBlob();
|
advertsBlob loadedAdverts = new advertsBlob();
|
||||||
advertConfig demoAdvert = new advertConfig();
|
advertConfig demoAdvert = new advertConfig();
|
||||||
demoAdvert.attachment = UUID.Zero.ToString();
|
demoAdvert.attachment = UUID.Zero.ToString();
|
||||||
|
|
@ -47,11 +50,13 @@ namespace BetterSecondbot.Adverts
|
||||||
SimpleIO io = new SimpleIO();
|
SimpleIO io = new SimpleIO();
|
||||||
if (SimpleIO.FileType(targetfile, "json") == false)
|
if (SimpleIO.FileType(targetfile, "json") == false)
|
||||||
{
|
{
|
||||||
|
LogFormater.Status("Creating new adverts file", true);
|
||||||
io.WriteJsonAdverts(loadedAdverts, targetfile);
|
io.WriteJsonAdverts(loadedAdverts, targetfile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (io.Exists(targetfile) == false)
|
if (io.Exists(targetfile) == false)
|
||||||
{
|
{
|
||||||
|
LogFormater.Status("Creating new adverts file", true);
|
||||||
io.WriteJsonAdverts(loadedAdverts, targetfile);
|
io.WriteJsonAdverts(loadedAdverts, targetfile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -115,10 +120,12 @@ namespace BetterSecondbot.Adverts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
groups.Add(selectedGroups);
|
groups.Add(selectedGroups);
|
||||||
|
LogFormater.Info("Loaded advert: ("+config.enabled+") "+ config.title+" "+config.days+" | "+config.hour+"h "+config.min+"m", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loadFromDockerEnv()
|
protected void loadFromDockerEnv()
|
||||||
{
|
{
|
||||||
|
LogFormater.Info("Loading adverts from ENV", true);
|
||||||
int loop = 1;
|
int loop = 1;
|
||||||
bool found = true;
|
bool found = true;
|
||||||
while (found == true)
|
while (found == true)
|
||||||
|
|
@ -140,7 +147,7 @@ namespace BetterSecondbot.Adverts
|
||||||
while(exitNow == false)
|
while(exitNow == false)
|
||||||
{
|
{
|
||||||
exitNow = true;
|
exitNow = true;
|
||||||
string value = getEnv("advert_" + loop.ToString() + "_group_" + loop2.ToString());
|
string value = getEnv("advert_" + loop2.ToString() + "_group_" + loop2.ToString());
|
||||||
if (helpers.notempty(value) == true)
|
if (helpers.notempty(value) == true)
|
||||||
{
|
{
|
||||||
groupentrys.Add(value);
|
groupentrys.Add(value);
|
||||||
|
|
@ -179,6 +186,10 @@ namespace BetterSecondbot.Adverts
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
DateTime moment = DateTime.Now;
|
DateTime moment = DateTime.Now;
|
||||||
|
if(lastTickMin == -1)
|
||||||
|
{
|
||||||
|
LogFormater.Info("Current time: "+moment.Hour.ToString()+":"+moment.Minute.ToString(), true);
|
||||||
|
}
|
||||||
if (lastTickMin != moment.Minute)
|
if (lastTickMin != moment.Minute)
|
||||||
{
|
{
|
||||||
lastTickMin = moment.Minute;
|
lastTickMin = moment.Minute;
|
||||||
|
|
@ -193,37 +204,41 @@ namespace BetterSecondbot.Adverts
|
||||||
int loop = 0;
|
int loop = 0;
|
||||||
while (loop < titles.Count)
|
while (loop < titles.Count)
|
||||||
{
|
{
|
||||||
|
bool noGo = false;
|
||||||
if (enabled[loop] == false)
|
if (enabled[loop] == false)
|
||||||
{
|
{
|
||||||
continue;
|
noGo = true;
|
||||||
}
|
}
|
||||||
if (activeDays[loop].Contains(dayofweek) == false)
|
if (activeDays[loop].Contains(dayofweek) == false)
|
||||||
{
|
{
|
||||||
continue;
|
noGo = true;
|
||||||
}
|
}
|
||||||
if ((activeHours[loop] != moment.Hour) && (activeHours[loop] != -1))
|
if ((activeHours[loop] != moment.Hour) && (activeHours[loop] != -1))
|
||||||
{
|
{
|
||||||
continue;
|
noGo = true;
|
||||||
}
|
}
|
||||||
if ((activeHours[loop] != moment.Minute) && (activeHours[loop] != -1))
|
if ((activeHours[loop] != moment.Minute) && (activeHours[loop] != -1))
|
||||||
{
|
{
|
||||||
continue;
|
noGo = true;
|
||||||
}
|
}
|
||||||
if (activeHours[loop] == -1)
|
if (activeHours[loop] == -1)
|
||||||
{
|
{
|
||||||
if ((moment.Minute != 0) && (moment.Minute != 30))
|
if ((moment.Minute != 0) && (moment.Minute != 30))
|
||||||
{
|
{
|
||||||
continue;
|
noGo = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (noGo == false)
|
||||||
|
{
|
||||||
TriggerAdvert(loop);
|
TriggerAdvert(loop);
|
||||||
|
}
|
||||||
loop++;
|
loop++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void TriggerAdvert(int advertID)
|
protected void TriggerAdvert(int advertID)
|
||||||
{
|
{
|
||||||
|
LogFormater.Info("Processing advert: "+advertID.ToString(), true);
|
||||||
foreach (UUID group in groups[advertID])
|
foreach (UUID group in groups[advertID])
|
||||||
{
|
{
|
||||||
if (asNotice[advertID] == true)
|
if (asNotice[advertID] == true)
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,15 @@ namespace BetterSecondBot
|
||||||
return Bot;
|
return Bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void TickAdverts()
|
||||||
|
{
|
||||||
|
Adverts.Tick();
|
||||||
|
}
|
||||||
protected void keep_alive()
|
protected void keep_alive()
|
||||||
{
|
{
|
||||||
while (Bot.KillMe == false)
|
while (Bot.KillMe == false)
|
||||||
{
|
{
|
||||||
|
TickAdverts();
|
||||||
string NewStatusMessage = Bot.GetStatus();
|
string NewStatusMessage = Bot.GetStatus();
|
||||||
NewStatusMessage = NewStatusMessage.Trim();
|
NewStatusMessage = NewStatusMessage.Trim();
|
||||||
if (NewStatusMessage != Bot.LastStatusMessage)
|
if (NewStatusMessage != Bot.LastStatusMessage)
|
||||||
|
|
@ -43,6 +48,7 @@ namespace BetterSecondBot
|
||||||
}
|
}
|
||||||
Thread.Sleep(1500);
|
Thread.Sleep(1500);
|
||||||
}
|
}
|
||||||
|
Adverts = null;
|
||||||
betterAtHomeService = null;
|
betterAtHomeService = null;
|
||||||
betterTracking = null;
|
betterTracking = null;
|
||||||
datastorage = null;
|
datastorage = null;
|
||||||
|
|
@ -68,6 +74,7 @@ namespace BetterSecondBot
|
||||||
public Cli(JsonConfig Config, bool as_docker, bool use_self_keep_alive)
|
public Cli(JsonConfig Config, bool as_docker, bool use_self_keep_alive)
|
||||||
{
|
{
|
||||||
exitBot = false;
|
exitBot = false;
|
||||||
|
LogFormater.Info("Starting cli");
|
||||||
if (helpers.botRequired(Config) == true)
|
if (helpers.botRequired(Config) == true)
|
||||||
{
|
{
|
||||||
Bot = new SecondBot();
|
Bot = new SecondBot();
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
{
|
{
|
||||||
StatusMessageHandler(null, new BetterSecondBot.bottypes.StatusMessageEvent(false, "None"));
|
StatusMessageHandler(null, new BetterSecondBot.bottypes.StatusMessageEvent(false, "None"));
|
||||||
}
|
}
|
||||||
|
|
||||||
string NewStatusMessage = GetStatus();
|
string NewStatusMessage = GetStatus();
|
||||||
if (NewStatusMessage != LastStatusMessage)
|
if (NewStatusMessage != LastStatusMessage)
|
||||||
{
|
{
|
||||||
|
|
@ -37,6 +38,7 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
LastStatusMessage = NewStatusMessage;
|
LastStatusMessage = NewStatusMessage;
|
||||||
if (HasBasicBot() == true)
|
if (HasBasicBot() == true)
|
||||||
{
|
{
|
||||||
|
controler.TickAdverts();
|
||||||
controler.getBot().Log2File(LogFormater.Status(LastStatusMessage, false), ConsoleLogLogLevel.Status);
|
controler.getBot().Log2File(LogFormater.Status(LastStatusMessage, false), ConsoleLogLogLevel.Status);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,64 @@ using BetterSecondBotShared.Static;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Timers;
|
||||||
|
using BetterSecondBotShared.logs;
|
||||||
|
|
||||||
namespace BetterSecondBot.DiscordSupervisor
|
namespace BetterSecondBot.DiscordSupervisor
|
||||||
{
|
{
|
||||||
public abstract class DiscordBot : DiscordInbound
|
public abstract class DiscordBot : DiscordInbound
|
||||||
{
|
{
|
||||||
|
protected Timer ReconnectTimer;
|
||||||
protected virtual async Task StartDiscordClientService()
|
protected virtual async Task StartDiscordClientService()
|
||||||
{
|
{
|
||||||
DiscordClient = new DiscordSocketClient();
|
DiscordClient = new DiscordSocketClient();
|
||||||
DiscordClient.Ready += DiscordClientReady;
|
DiscordClient.Ready += DiscordClientReady;
|
||||||
DiscordClient.LoggedOut += DiscordClientLoggedOut;
|
DiscordClient.LoggedOut += DiscordClientLoggedOut;
|
||||||
|
DiscordClient.LoggedIn += DicordClientLoggedin;
|
||||||
DiscordClient.MessageReceived += DiscordClientMessageReceived;
|
DiscordClient.MessageReceived += DiscordClientMessageReceived;
|
||||||
|
ReconnectTimer = new Timer();
|
||||||
|
ReconnectTimer.Interval = 10000;
|
||||||
|
ReconnectTimer.Elapsed += ReconnectTimerEvent;
|
||||||
|
ReconnectTimer.AutoReset = false;
|
||||||
|
ReconnectTimer.Enabled = false;
|
||||||
|
LogFormater.Info("Discord is starting", true);
|
||||||
await DiscordClient.LoginAsync(TokenType.Bot, myconfig.DiscordFull_Token);
|
await DiscordClient.LoginAsync(TokenType.Bot, myconfig.DiscordFull_Token);
|
||||||
_ = DiscordClient.StartAsync();
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task DiscordClientLoggedOut()
|
||||||
|
{
|
||||||
|
LogFormater.Info("Discord has logged out", true);
|
||||||
|
ReconnectTimer = new Timer();
|
||||||
|
ReconnectTimer.Interval = 10000;
|
||||||
|
ReconnectTimer.Elapsed += ReconnectTimerEvent;
|
||||||
|
ReconnectTimer.AutoReset = false;
|
||||||
|
ReconnectTimer.Enabled = false;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual async Task<Task> DicordClientLoggedin()
|
||||||
|
{
|
||||||
|
LogFormater.Info("Discord has logged in", true);
|
||||||
|
await DiscordClient.StartAsync().ConfigureAwait(false);
|
||||||
|
ReconnectTimer = new Timer();
|
||||||
|
ReconnectTimer.Interval = 10000;
|
||||||
|
ReconnectTimer.Elapsed += ReconnectTimerEvent;
|
||||||
|
ReconnectTimer.AutoReset = false;
|
||||||
|
ReconnectTimer.Enabled = false;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReconnectTimerEvent(Object source, System.Timers.ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
ReconnectTimer.Enabled = false;
|
||||||
|
_ = StartDiscordClientService().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual async Task<Task> DiscordClientReady()
|
protected virtual async Task<Task> DiscordClientReady()
|
||||||
{
|
{
|
||||||
|
LogFormater.Info("Discord is active", true);
|
||||||
|
ReconnectTimer.Enabled = false;
|
||||||
await DiscordClient.SetStatusAsync(Discord.UserStatus.Idle);
|
await DiscordClient.SetStatusAsync(Discord.UserStatus.Idle);
|
||||||
await DiscordClient.SetGameAsync("Not connected", null, ActivityType.CustomStatus);
|
await DiscordClient.SetGameAsync("Not connected", null, ActivityType.CustomStatus);
|
||||||
DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
|
DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace BetterSecondBot.DiscordSupervisor
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
protected Task DiscordClientLoggedOut()
|
protected virtual Task DiscordClientLoggedOut()
|
||||||
{
|
{
|
||||||
DiscordClientConnected = false;
|
DiscordClientConnected = false;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
|
||||||
18
BetterSecondbot/Properties/PublishProfiles/Windows.pubxml
Normal file
18
BetterSecondbot/Properties/PublishProfiles/Windows.pubxml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Any CPU</Platform>
|
||||||
|
<PublishDir>D:\publish</PublishDir>
|
||||||
|
<PublishProtocol>FileSystem</PublishProtocol>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
<SelfContained>true</SelfContained>
|
||||||
|
<PublishSingleFile>True</PublishSingleFile>
|
||||||
|
<PublishReadyToRun>False</PublishReadyToRun>
|
||||||
|
<PublishTrimmed>False</PublishTrimmed>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
|
|
@ -32227,6 +32227,12 @@
|
||||||
<member name="F:OpenMetaverse.Parcel.Media">
|
<member name="F:OpenMetaverse.Parcel.Media">
|
||||||
<summary>A struct containing media details</summary>
|
<summary>A struct containing media details</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="F:OpenMetaverse.Parcel.AnyAVSounds">
|
||||||
|
<summary> true if avatars outside can hear any sounds avatars inside play</summary>
|
||||||
|
</member>
|
||||||
|
<member name="F:OpenMetaverse.Parcel.GroupAVSounds">
|
||||||
|
<summary> true if group members outside can hear any sounds avatars inside play</summary>
|
||||||
|
</member>
|
||||||
<member name="M:OpenMetaverse.Parcel.ToString">
|
<member name="M:OpenMetaverse.Parcel.ToString">
|
||||||
<summary>
|
<summary>
|
||||||
Displays a parcel object in string format
|
Displays a parcel object in string format
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue