Skip to content

Commit d2b8374

Browse files
committed
Add NotificationTrigger
1 parent 9b6254b commit d2b8374

16 files changed

Lines changed: 496 additions & 35 deletions

SteamChatBot/App.config

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<configuration>
3-
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5-
</startup>
6-
<runtime>
7-
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8-
<dependentAssembly>
9-
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
10-
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
11-
</dependentAssembly>
12-
<dependentAssembly>
13-
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
14-
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
15-
</dependentAssembly>
16-
</assemblyBinding>
17-
</runtime>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
11+
</dependentAssembly>
12+
<dependentAssembly>
13+
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
14+
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
15+
</dependentAssembly>
16+
<dependentAssembly>
17+
<assemblyIdentity name="System" publicKeyToken="b77a5c561934e089" culture="neutral" />
18+
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
19+
</dependentAssembly>
20+
<dependentAssembly>
21+
<assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture="neutral" />
22+
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
23+
</dependentAssembly>
24+
<dependentAssembly>
25+
<assemblyIdentity name="System.Web" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
26+
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
27+
</dependentAssembly>
28+
<dependentAssembly>
29+
<assemblyIdentity name="System.Xml" publicKeyToken="b77a5c561934e089" culture="neutral" />
30+
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
31+
</dependentAssembly>
32+
<dependentAssembly>
33+
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
34+
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
35+
</dependentAssembly>
36+
</assemblyBinding>
37+
</runtime>
1838
</configuration>

SteamChatBot/Bot.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class Bot
2929
public static SteamUser steamUser = steamClient.GetHandler<SteamUser>();
3030
public static SteamFriends steamFriends = steamClient.GetHandler<SteamFriends>();
3131
public static SteamGameCoordinator steamGC = steamClient.GetHandler<SteamGameCoordinator>();
32-
3332
public static SteamGuardAccount steamGuardAccount = new SteamGuardAccount();
3433

3534
#endregion

SteamChatBot/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<ListBoxItem x:Name="lockChatTrigger" Content="LockChatTrigger - Locks the chat room"/>
7171
<ListBoxItem x:Name="moderateChatTrigger" Content="ModerateChatTrigger - Moderates a chat room"/>
7272
<ListBoxItem x:Name="noteTrigger" Content="NoteTrigger - Saves notes than can be accessed by anyone in the chat"/>
73+
<ListBoxItem x:Name="notificationTrigger" Content="NotificationTrigger - Sends users notifications"/>
7374
<ListBoxItem x:Name="playGameTrigger" Content="PlayGameTrigger - Plays a game (AppID)"/>
7475
<ListBoxItem x:Name="unbanTrigger" Content="UnbanTrigger - Unbans a user from chat"/>
7576
<ListBoxItem x:Name="unmoderateChatTrigger" Content="UnmoderateChatTrigger - Unmoderates the chat"/>

SteamChatBot/MainWindow.xaml.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ private void plusTriggerButton_Click(object sender, RoutedEventArgs e)
239239
AntiSpamTriggerOptions asto = new AntiSpamTriggerOptions();
240240
DiscordOptions _do = new DiscordOptions(); // "do" is a keyword
241241
NoteTriggerOptions nto = new NoteTriggerOptions();
242+
NotificationOptions no = new NotificationOptions();
243+
242244
TriggerOptionsBase tob = new TriggerOptionsBase();
243245

244246
if (selected == "isUpTrigger" || selected == "leaveChatTrigger" || selected == "kickTrigger"
@@ -405,6 +407,27 @@ private void plusTriggerButton_Click(object sender, RoutedEventArgs e)
405407
Bot.triggers.Add(trigger);
406408
}
407409
}
410+
else if(selected == "notificationTrigger")
411+
{
412+
NotificationOptionsWindow now = new NotificationOptionsWindow();
413+
now.ShowDialog();
414+
if(now.DialogResult.HasValue && now.DialogResult == true)
415+
{
416+
NotificationOptions now_no = now.NO;
417+
NoCommand now_nc = now.NC;
418+
nc = GetNoCommandOptions(now_nc);
419+
no = GetNotificationOptions(now_no);
420+
type = (TriggerType)Enum.Parse(typeof(TriggerType), char.ToUpper(selected[0]) + selected.Substring(1));
421+
422+
tob.NotificationOptions = no;
423+
tob.NotificationOptions.NoCommand = nc;
424+
tob.Name = Name;
425+
tob.Type = type;
426+
addedTriggersListBox.Items.Add(string.Format("{0} - {1}", no.Name, type));
427+
BaseTrigger trigger = (BaseTrigger)Activator.CreateInstance(Type.GetType("SteamChatBot.Triggers." + type.ToString()), type, no.Name, tob);
428+
Bot.triggers.Add(trigger);
429+
}
430+
}
408431
else
409432
{
410433
MessageBox.Show("Unknown Trigger. Please contact the developer.", "Error", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
@@ -556,6 +579,25 @@ private NoteTriggerOptions GetNoteTriggerOptions(NoteTriggerOptions nto)
556579
catch (Exception e) { return null; }
557580
}
558581

582+
private NotificationOptions GetNotificationOptions(NotificationOptions no)
583+
{
584+
try
585+
{
586+
return new NotificationOptions
587+
{
588+
Name = no.Name,
589+
NoCommand = no.NoCommand,
590+
APICommand = no.APICommand,
591+
ClearCommand = no.ClearCommand,
592+
DBFile = no.DBFile,
593+
FilterCommand = no.FilterCommand,
594+
SeenCommand = no.SeenCommand,
595+
SaveTimer = no.SaveTimer
596+
};
597+
}
598+
catch (Exception e) { return null; }
599+
}
600+
559601
#endregion
560602
}
561603
}

SteamChatBot/SteamChatBot.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@
131131
<HintPath>..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath>
132132
<Private>True</Private>
133133
</Reference>
134+
<Reference Include="PushbulletSharp, Version=2.3.3.0, Culture=neutral, processorArchitecture=MSIL">
135+
<HintPath>..\packages\PushBulletSharp.2.3.3\lib\portable-windows8+net45\PushbulletSharp.dll</HintPath>
136+
<Private>True</Private>
137+
</Reference>
134138
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
135139
<HintPath>..\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll</HintPath>
136140
<Private>True</Private>
@@ -247,6 +251,7 @@
247251
<Compile Include="Triggers\LinkNameTrigger.cs" />
248252
<Compile Include="Triggers\ModerateTrigger.cs" />
249253
<Compile Include="Triggers\NoteTrigger.cs" />
254+
<Compile Include="Triggers\NotificationTrigger.cs" />
250255
<Compile Include="Triggers\PlayGameTrigger.cs" />
251256
<Compile Include="Triggers\TriggerOptions\AntiSpamTriggerOptions.cs" />
252257
<Compile Include="Triggers\TriggerOptions\ChatCommand.cs" />
@@ -255,6 +260,7 @@
255260
<Compile Include="Triggers\TriggerOptions\DiscordOptions.cs" />
256261
<Compile Include="Triggers\TriggerOptions\NoCommand.cs" />
257262
<Compile Include="Triggers\TriggerOptions\NoteTriggerOptions.cs" />
263+
<Compile Include="Triggers\TriggerOptions\NotificationOptions.cs" />
258264
<Compile Include="Triggers\TriggerOptions\OptionType.cs" />
259265
<Compile Include="Triggers\TriggerOptions\TriggerLists.cs" />
260266
<Compile Include="Triggers\TriggerOptions\TriggerNumbers.cs" />
@@ -280,6 +286,9 @@
280286
<Compile Include="Triggers\TriggerOptions\Windows\NoteTriggerOptionsWindow.xaml.cs">
281287
<DependentUpon>NoteTriggerOptionsWindow.xaml</DependentUpon>
282288
</Compile>
289+
<Compile Include="Triggers\TriggerOptions\Windows\NotificationOptionsWindow.xaml.cs">
290+
<DependentUpon>NotificationOptionsWindow.xaml</DependentUpon>
291+
</Compile>
283292
<Compile Include="Triggers\TriggerOptions\Windows\TriggerListWindow.xaml.cs">
284293
<DependentUpon>TriggerListWindow.xaml</DependentUpon>
285294
</Compile>
@@ -330,6 +339,10 @@
330339
<SubType>Designer</SubType>
331340
<Generator>MSBuild:Compile</Generator>
332341
</Page>
342+
<Page Include="Triggers\TriggerOptions\Windows\NotificationOptionsWindow.xaml">
343+
<SubType>Designer</SubType>
344+
<Generator>MSBuild:Compile</Generator>
345+
</Page>
333346
<Page Include="Triggers\TriggerOptions\Windows\TriggerListWindow.xaml">
334347
<SubType>Designer</SubType>
335348
<Generator>MSBuild:Compile</Generator>

SteamChatBot/SteamHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace SteamChatBot
1010
{
1111
class SteamHelper
1212
{
13+
public Dictionary<SteamID, string> ChatRoomMembers { get; set; }
14+
1315
public static SteamID ToClanID(SteamID steamID)
1416
{
1517
if(steamID.AccountInstance == (uint)SteamID.ChatInstanceFlags.Clan)

SteamChatBot/Triggers/BaseTrigger.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public BaseTrigger(TriggerType type, string name, TriggerOptionsBase options)
3333
else if (options.TriggerLists != null && options.TriggerNumbers != null) OptionsType = OptionType.ListsAndNumbers;
3434
else if (options.TriggerLists != null) OptionsType = OptionType.JustLists;
3535
else if (options.NoteTriggerOptions != null) OptionsType = OptionType.NoteTriggerOptions;
36+
else if (options.NotificationOptions != null) OptionsType = OptionType.NotificationOptions;
3637

3738
Type = type;
3839
Name = name;
@@ -77,7 +78,8 @@ public void SaveTrigger()
7778
TriggerNumbers = Options.TriggerNumbers,
7879
AntiSpamTriggerOptions = Options.AntiSpamTriggerOptions,
7980
DiscordOptions = Options.DiscordOptions,
80-
NoteTriggerOptions = Options.NoteTriggerOptions
81+
NoteTriggerOptions = Options.NoteTriggerOptions,
82+
NotificationOptions = Options.NotificationOptions
8183
};
8284
string json = JsonConvert.SerializeObject(options, Formatting.Indented);
8385
File.WriteAllText(Bot.username + "/triggers/" + Name + ".json", json);
@@ -160,6 +162,9 @@ public static List<BaseTrigger> ReadTriggers()
160162
case TriggerType.NoteTrigger:
161163
temp.Add(new NoteTrigger(type, name, options));
162164
break;
165+
case TriggerType.NotificationTrigger:
166+
temp.Add(new NotificationTrigger(type, name, options));
167+
break;
163168
case TriggerType.PlayGameTrigger:
164169
temp.Add(new PlayGameTrigger(type, name, options));
165170
break;
@@ -762,6 +767,9 @@ protected void SendMessageAfterDelay(SteamID steamID, string message, bool room)
762767
case OptionType.NoteTriggerOptions:
763768
delay = Options.NoteTriggerOptions.NoCommand.TriggerNumbers.Delay == null ? 0 : Options.NoteTriggerOptions.NoCommand.TriggerNumbers.Delay.Value;
764769
break;
770+
case OptionType.NotificationOptions:
771+
delay = Options.NotificationOptions.NoCommand.TriggerNumbers.Delay == null ? 0 : Options.NotificationOptions.NoCommand.TriggerNumbers.Delay.Value;
772+
break;
765773
}
766774
}
767775
catch (NullReferenceException nre) { }
@@ -860,6 +868,9 @@ protected bool CheckIgnores(SteamID toID, SteamID fromID)
860868
case OptionType.NoteTriggerOptions:
861869
ignore = Options.NoteTriggerOptions.NoCommand.TriggerLists.Ignore;
862870
break;
871+
case OptionType.NotificationOptions:
872+
ignore = Options.NotificationOptions.NoCommand.TriggerLists.Ignore;
873+
break;
863874
}
864875
}
865876
catch (NullReferenceException nre) { }
@@ -923,6 +934,9 @@ protected bool CheckRoom(SteamID toID)
923934
case OptionType.NoteTriggerOptions:
924935
rooms = Options.NoteTriggerOptions.NoCommand.TriggerLists.Rooms;
925936
break;
937+
case OptionType.NotificationOptions:
938+
rooms = Options.NotificationOptions.NoCommand.TriggerLists.Rooms;
939+
break;
926940
}
927941
}
928942
catch (NullReferenceException nre) { }
@@ -988,6 +1002,9 @@ protected bool CheckUser(SteamID fromID)
9881002
case OptionType.NoteTriggerOptions:
9891003
users = Options.NoteTriggerOptions.NoCommand.TriggerLists.User;
9901004
break;
1005+
case OptionType.NotificationOptions:
1006+
users = Options.NotificationOptions.NoCommand.TriggerLists.User;
1007+
break;
9911008
}
9921009
}
9931010
catch (NullReferenceException nre) { }
@@ -1046,6 +1063,9 @@ protected bool RandomRoll()
10461063
case OptionType.NoteTriggerOptions:
10471064
prob = Options.NoteTriggerOptions.NoCommand.TriggerNumbers.Probability == null ? 1 : Options.NoteTriggerOptions.NoCommand.TriggerNumbers.Probability.Value;
10481065
break;
1066+
case OptionType.NotificationOptions:
1067+
prob = Options.NotificationOptions.NoCommand.TriggerNumbers.Probability == null ? 1 : Options.NotificationOptions.NoCommand.TriggerNumbers.Probability.Value;
1068+
break;
10491069

10501070
}
10511071
}
@@ -1101,6 +1121,9 @@ protected void DisableForTimeout()
11011121
case OptionType.NoteTriggerOptions:
11021122
to = Options.NoteTriggerOptions.NoCommand.TriggerNumbers.Timeout == null ? 0 : Options.NoteTriggerOptions.NoCommand.TriggerNumbers.Timeout.Value;
11031123
break;
1124+
case OptionType.NotificationOptions:
1125+
to = Options.NotificationOptions.NoCommand.TriggerNumbers.Timeout == null ? 0 : Options.NotificationOptions.NoCommand.TriggerNumbers.Timeout.Value;
1126+
break;
11041127

11051128
}
11061129
}

SteamChatBot/Triggers/NoteTrigger.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private void SaveNoteTimer_Elapsed(object sender, ElapsedEventArgs e)
2929
Log.Instance.Silly("{0}/{1}: Wrote notes to {0}/notes.json", Bot.username, Name);
3030
}
3131

32-
public override bool OnLoggedOn()
32+
public override bool onLoggedOn()
3333
{
3434
try
3535
{
@@ -44,6 +44,7 @@ public override bool OnLoggedOn()
4444
catch (Exception e)
4545
{
4646
Log.Instance.Error(e.Message + ": " + e.StackTrace);
47+
return false;
4748
}
4849

4950
if (Options.NoteTriggerOptions.Notes == null)

0 commit comments

Comments
 (0)