Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
Created Countdown Module
Browse files Browse the repository at this point in the history
  • Loading branch information
Supernova4422 committed Jan 21, 2017
1 parent 32e39dc commit 15f7c38
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 39 deletions.
21 changes: 5 additions & 16 deletions ApplicationInterfaces/ApplicationInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public void AssignUserHandler(UserHandler userhandler)
userhandler.MainChatRoomJoin += EnterMainChatRoom;
userhandler.MainChatRoomLeave += LeaveMainChatroom;
userhandler.ChatMemberInfoEvent += ChatMemberInfoEvent;


userhandler.SetStatusmessage += SetStatusMessage;
}


Expand All @@ -106,20 +105,6 @@ public class ChatMemberInfoEventArgs
bool IsAdmin;
}

/*
public event EventHandler<ChatMemberInfoEventArgs> ChatMemberInfoEvent;
protected virtual void ChatMemberInfoProcessEvent(ChatMemberInfoEventArgs e)
{
// Make a temporary copy of the event to avoid possibility of
// a race condition if the last subscriber unsubscribes
// immediately after the null check and before the event is raised.
EventHandler<ChatMemberInfoEventArgs> handler = ChatMemberInfoEvent;
if (handler != null)
{
handler(this, e);
}
}
*/
public event EventHandler<MessageEventArgs> ChatRoomMessageEvent;

//The event-invoking method that derived classes can override.
Expand Down Expand Up @@ -180,6 +165,10 @@ protected virtual void AnnounceLoginCompleted()
}
}

public event EventHandler<string> SetStatusMessageEvent;

public abstract void SetStatusMessage(object sender, string message);

public abstract void ReceiveChatMemberInfo(ChatroomEntity ChatroomEntity, bool AdminStatus);

public abstract void EnterChatRoom (object sender, ChatroomEntity ChatroomEntity);
Expand Down
5 changes: 5 additions & 0 deletions ApplicationInterfaces/Discord/DiscordInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,10 @@ public override void BroadCastMessage(object sender, string message)

}
}

public override void SetStatusMessage(object sender, string message)
{
// _client.SetGame(message);
}
}
}
20 changes: 19 additions & 1 deletion ApplicationInterfaces/Steam/SteamInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Security.Cryptography;
using Newtonsoft.Json;
using SteamKit2.Internal;

namespace SteamBotLite
{
Expand Down Expand Up @@ -498,6 +499,23 @@ public override string GetUsername()
return SteamFriends.GetPersonaName();
}


public override void SetStatusMessage(object sender, string message)
{
var request = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);

var gamePlayed = new CMsgClientGamesPlayed.GamePlayed();

if (!string.IsNullOrEmpty(message))
{
gamePlayed.game_id = 12350489788975939584;
gamePlayed.game_extra_info = message;
}

request.Body.games_played.Add(gamePlayed);

steamClient.Send(request);
}


}
}
1 change: 1 addition & 0 deletions SteamBotLite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Compile Include="ApplicationInterfaces\Discord\Accounts\DiscordAccountVFun.cs" />
<Compile Include="UserHandlers\VBot\VBot\Interfaces\HTMLFileFromArray.cs" />
<Compile Include="UserHandlers\VBot\VBot\Interfaces\Interface1.cs" />
<Compile Include="UserHandlers\VBot\VBot\Modules\CountDownModule.cs" />
<Compile Include="UserHandlers\VBot\VBot\Modules\MapWebServer.cs" />
<Compile Include="UserHandlers\VBot\VBot\Modules\SearchClass.cs" />
<Compile Include="UserHandlers\VBot\VBot.cs" />
Expand Down
14 changes: 13 additions & 1 deletion UserHandlers/UserHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,20 @@ public virtual void SendChatRoomMessageProcessEvent(MessageEventArgs e)
}
}

public event EventHandler<string> SetStatusmessage;


//The event-invoking method that derived classes can override.
public virtual void SetStatusmessageEvent(string e)
{
// Make a temporary copy of the event to avoid possibility of
// a race condition if the last subscriber unsubscribes
// immediately after the null check and before the event is raised.
EventHandler<string> handler = SetStatusmessage;
if (handler != null)
{
handler(this, e);
}
}



Expand Down
7 changes: 4 additions & 3 deletions UserHandlers/VBot/VBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class VBot : UserHandler , HTMLFileFromArrayListiners
SearchModule searchModule;
ImpNaoModule impnaomodule;
ServerListHolder serverlistmodule;

MapWebServer WebServer;
CountDownModule countdownmodule;
MapWebServer WebServer;

public UsersModule usersModule;

Expand Down Expand Up @@ -66,9 +66,10 @@ public VBot()
searchModule = new SearchModule(this, jsconfig);
adminmodule = new AdminModule(this, jsconfig);

countdownmodule = new CountDownModule(this, jsconfig);


ModuleList = new List<BaseModule> { motdModule,mapModule,serverModule,usersModule,replyModule,adminmodule,searchModule, WebServer, serverlistmodule };
ModuleList = new List<BaseModule> { motdModule,mapModule,serverModule,usersModule,replyModule,adminmodule,searchModule, WebServer, serverlistmodule , countdownmodule };
Console.WriteLine("Modules loaded and ModuleList intitialised");

//We run this to allow the modules to partake in actions requiring all to be loaded
Expand Down
24 changes: 23 additions & 1 deletion UserHandlers/VBot/VBot/Modules/AdminModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public AdminModule(VBot bot, Dictionary<string, object> Jsconfig) : base(bot, Js
adminCommands.Add(new AddModule(bot, this));
adminCommands.Add(new GetAllModules(bot, this));
adminCommands.Add(new Rejoin(bot, this));

adminCommands.Add(new SetStatusMessage(bot, this));
}

public override string getPersistentData()
Expand Down Expand Up @@ -68,6 +68,27 @@ public override void OnAllModulesLoaded()

}

private class SetStatusMessage : BaseCommand
{
// Command to query if a server is active
VBot bot;

public SetStatusMessage(VBot bot, AdminModule module) : base(bot, "!Status")
{
this.bot = bot;
}
protected override string exec(MessageEventArgs Msg, string param)
{
bot.SetStatusmessageEvent(param);
return "Status has been updated";
}

private void Bot_SetStatusmessage(object sender, string e)
{
throw new NotImplementedException();
}
}

private class Reboot : BaseCommand
{
// Command to query if a server is active
Expand Down Expand Up @@ -96,6 +117,7 @@ public Rejoin(VBot bot, AdminModule module) : base(bot, "!Rejoin")
}
protected override string exec(MessageEventArgs Msg, string param)
{

module.SteamBot.FireMainChatRoomEvent(UserHandler.ChatroomEventEnum.LeaveChat);
module.SteamBot.FireMainChatRoomEvent(UserHandler.ChatroomEventEnum.EnterChat);
return "Rejoined!";
Expand Down
51 changes: 51 additions & 0 deletions UserHandlers/VBot/VBot/Modules/CountDownModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Newtonsoft.Json;
using SteamKit2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace SteamBotLite
{
class CountDownModule : MotdModule
{
public CountDownModule(VBot bot, Dictionary<string, object> Jsconfig) : base(bot, Jsconfig){ }

public override string GetName()
{
return "!Countdown";
}
public override int DefaultPostCountLimit()
{
return 24 * 60;
}
/// <summary>
/// Posts the MOTD to the group chat
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public override void MotdPost(object sender, EventArgs e)
{
if (message != null && !message.Equals(string.Empty))
{
double hoursdata = (postCountLimit - postCount) / 60;
Math.Ceiling(hoursdata);

string hours = (hoursdata.ToString().PadLeft(2, '0'));
string minutes = ((postCountLimit - postCount) % 60).ToString().PadLeft(2, '0');
message = hours + ":" + minutes;

userhandler.SetStatusmessageEvent(message);

postCount++;
if (postCount > postCountLimit)
message = null;
savePersistentData();
}
}


}
}

0 comments on commit 15f7c38

Please sign in to comment.