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 BetterSecondBotShared.IO;
|
||||
using BetterSecondBotShared.Json;
|
||||
using BetterSecondBotShared.logs;
|
||||
using BetterSecondBotShared.Static;
|
||||
using Newtonsoft.Json;
|
||||
using OpenMetaverse;
|
||||
|
|
@ -17,7 +18,8 @@ namespace BetterSecondbot.Adverts
|
|||
public advertsService(Cli Master, bool LoadFromDocker)
|
||||
{
|
||||
controler = Master;
|
||||
if(LoadFromDocker == true)
|
||||
LogFormater.Info("Starting adverts service", true);
|
||||
if (LoadFromDocker == true)
|
||||
{
|
||||
loadFromDockerEnv();
|
||||
}
|
||||
|
|
@ -29,6 +31,7 @@ namespace BetterSecondbot.Adverts
|
|||
|
||||
protected void loadFromDisk()
|
||||
{
|
||||
LogFormater.Info("Loading adverts from Disk", true);
|
||||
advertsBlob loadedAdverts = new advertsBlob();
|
||||
advertConfig demoAdvert = new advertConfig();
|
||||
demoAdvert.attachment = UUID.Zero.ToString();
|
||||
|
|
@ -47,11 +50,13 @@ namespace BetterSecondbot.Adverts
|
|||
SimpleIO io = new SimpleIO();
|
||||
if (SimpleIO.FileType(targetfile, "json") == false)
|
||||
{
|
||||
LogFormater.Status("Creating new adverts file", true);
|
||||
io.WriteJsonAdverts(loadedAdverts, targetfile);
|
||||
return;
|
||||
}
|
||||
if (io.Exists(targetfile) == false)
|
||||
{
|
||||
LogFormater.Status("Creating new adverts file", true);
|
||||
io.WriteJsonAdverts(loadedAdverts, targetfile);
|
||||
return;
|
||||
}
|
||||
|
|
@ -115,10 +120,12 @@ namespace BetterSecondbot.Adverts
|
|||
}
|
||||
}
|
||||
groups.Add(selectedGroups);
|
||||
LogFormater.Info("Loaded advert: ("+config.enabled+") "+ config.title+" "+config.days+" | "+config.hour+"h "+config.min+"m", true);
|
||||
}
|
||||
|
||||
protected void loadFromDockerEnv()
|
||||
{
|
||||
LogFormater.Info("Loading adverts from ENV", true);
|
||||
int loop = 1;
|
||||
bool found = true;
|
||||
while (found == true)
|
||||
|
|
@ -140,7 +147,7 @@ namespace BetterSecondbot.Adverts
|
|||
while(exitNow == false)
|
||||
{
|
||||
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)
|
||||
{
|
||||
groupentrys.Add(value);
|
||||
|
|
@ -179,6 +186,10 @@ namespace BetterSecondbot.Adverts
|
|||
public void Tick()
|
||||
{
|
||||
DateTime moment = DateTime.Now;
|
||||
if(lastTickMin == -1)
|
||||
{
|
||||
LogFormater.Info("Current time: "+moment.Hour.ToString()+":"+moment.Minute.ToString(), true);
|
||||
}
|
||||
if (lastTickMin != moment.Minute)
|
||||
{
|
||||
lastTickMin = moment.Minute;
|
||||
|
|
@ -193,37 +204,41 @@ namespace BetterSecondbot.Adverts
|
|||
int loop = 0;
|
||||
while (loop < titles.Count)
|
||||
{
|
||||
bool noGo = false;
|
||||
if (enabled[loop] == false)
|
||||
{
|
||||
continue;
|
||||
noGo = true;
|
||||
}
|
||||
if (activeDays[loop].Contains(dayofweek) == false)
|
||||
{
|
||||
continue;
|
||||
noGo = true;
|
||||
}
|
||||
if ((activeHours[loop] != moment.Hour) && (activeHours[loop] != -1))
|
||||
{
|
||||
continue;
|
||||
noGo = true;
|
||||
}
|
||||
if ((activeHours[loop] != moment.Minute) && (activeHours[loop] != -1))
|
||||
{
|
||||
continue;
|
||||
noGo = true;
|
||||
}
|
||||
if (activeHours[loop] == -1)
|
||||
{
|
||||
if ((moment.Minute != 0) && (moment.Minute != 30))
|
||||
{
|
||||
continue;
|
||||
noGo = true;
|
||||
}
|
||||
}
|
||||
TriggerAdvert(loop);
|
||||
if (noGo == false)
|
||||
{
|
||||
TriggerAdvert(loop);
|
||||
}
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
|
||||
protected void TriggerAdvert(int advertID)
|
||||
{
|
||||
|
||||
LogFormater.Info("Processing advert: "+advertID.ToString(), true);
|
||||
foreach (UUID group in groups[advertID])
|
||||
{
|
||||
if (asNotice[advertID] == true)
|
||||
|
|
|
|||
|
|
@ -27,10 +27,15 @@ namespace BetterSecondBot
|
|||
return Bot;
|
||||
}
|
||||
|
||||
public void TickAdverts()
|
||||
{
|
||||
Adverts.Tick();
|
||||
}
|
||||
protected void keep_alive()
|
||||
{
|
||||
while (Bot.KillMe == false)
|
||||
{
|
||||
TickAdverts();
|
||||
string NewStatusMessage = Bot.GetStatus();
|
||||
NewStatusMessage = NewStatusMessage.Trim();
|
||||
if (NewStatusMessage != Bot.LastStatusMessage)
|
||||
|
|
@ -43,6 +48,7 @@ namespace BetterSecondBot
|
|||
}
|
||||
Thread.Sleep(1500);
|
||||
}
|
||||
Adverts = null;
|
||||
betterAtHomeService = null;
|
||||
betterTracking = null;
|
||||
datastorage = null;
|
||||
|
|
@ -68,6 +74,7 @@ namespace BetterSecondBot
|
|||
public Cli(JsonConfig Config, bool as_docker, bool use_self_keep_alive)
|
||||
{
|
||||
exitBot = false;
|
||||
LogFormater.Info("Starting cli");
|
||||
if (helpers.botRequired(Config) == true)
|
||||
{
|
||||
Bot = new SecondBot();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
{
|
||||
StatusMessageHandler(null, new BetterSecondBot.bottypes.StatusMessageEvent(false, "None"));
|
||||
}
|
||||
|
||||
string NewStatusMessage = GetStatus();
|
||||
if (NewStatusMessage != LastStatusMessage)
|
||||
{
|
||||
|
|
@ -37,6 +38,7 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
LastStatusMessage = NewStatusMessage;
|
||||
if (HasBasicBot() == true)
|
||||
{
|
||||
controler.TickAdverts();
|
||||
controler.getBot().Log2File(LogFormater.Status(LastStatusMessage, false), ConsoleLogLogLevel.Status);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -6,23 +6,64 @@ using BetterSecondBotShared.Static;
|
|||
using Discord.WebSocket;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
using System.Timers;
|
||||
using BetterSecondBotShared.logs;
|
||||
|
||||
namespace BetterSecondBot.DiscordSupervisor
|
||||
{
|
||||
public abstract class DiscordBot : DiscordInbound
|
||||
{
|
||||
protected Timer ReconnectTimer;
|
||||
protected virtual async Task StartDiscordClientService()
|
||||
{
|
||||
DiscordClient = new DiscordSocketClient();
|
||||
DiscordClient.Ready += DiscordClientReady;
|
||||
DiscordClient.LoggedOut += DiscordClientLoggedOut;
|
||||
DiscordClient.LoggedIn += DicordClientLoggedin;
|
||||
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);
|
||||
_ = 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()
|
||||
{
|
||||
LogFormater.Info("Discord is active", true);
|
||||
ReconnectTimer.Enabled = false;
|
||||
await DiscordClient.SetStatusAsync(Discord.UserStatus.Idle);
|
||||
await DiscordClient.SetGameAsync("Not connected", null, ActivityType.CustomStatus);
|
||||
DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace BetterSecondBot.DiscordSupervisor
|
|||
}
|
||||
return false;
|
||||
}
|
||||
protected Task DiscordClientLoggedOut()
|
||||
protected virtual Task DiscordClientLoggedOut()
|
||||
{
|
||||
DiscordClientConnected = false;
|
||||
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">
|
||||
<summary>A struct containing media details</summary>
|
||||
</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">
|
||||
<summary>
|
||||
Displays a parcel object in string format
|
||||
|
|
|
|||
Loading…
Reference in a new issue