Browse Source

Added new modules.

Fixed some minor bugs.
Revamped UI to allow viewing of multiple servers/channels.
master
Teknikode 8 years ago
parent
commit
3aacb21720
  1. 148
      Combot.Servers.Release.config
  2. 27
      Combot.sln
  3. 5
      Combot/Bot.cs
  4. 26
      Combot/Modules/Module.cs
  5. 7
      IRCServices/IRC.cs
  6. 80
      IRCServices/SendCommand.cs
  7. 23
      Interface/BufferInfo.cs
  8. 1
      Interface/Interface.csproj
  9. 25
      Interface/MainWindow.xaml
  10. 306
      Interface/ViewModels/MainViewModel.cs
  11. 53
      Modules/Help/Help.cs
  12. 262
      Modules/Introductions/Introductions.cs
  13. 6
      Modules/Introductions/Module.config
  14. 8
      Modules/Logging/Logging.cs
  15. 1
      Modules/Logging/Logging.csproj
  16. 161
      Modules/Messaging/Messaging.cs
  17. 74
      Modules/Messaging/Messaging.csproj
  18. 67
      Modules/Messaging/Module.config
  19. 36
      Modules/Messaging/Properties/AssemblyInfo.cs
  20. 60
      Modules/Quotes/Module.config
  21. 36
      Modules/Quotes/Properties/AssemblyInfo.cs
  22. 122
      Modules/Quotes/Quotes.cs
  23. 74
      Modules/Quotes/Quotes.csproj
  24. 49
      Modules/Seen/Module.config
  25. 36
      Modules/Seen/Properties/AssemblyInfo.cs
  26. 228
      Modules/Seen/Seen.cs
  27. 74
      Modules/Seen/Seen.csproj
  28. 2
      Modules/Url Parsing/Url_Parsing.cs
  29. 2
      Modules/Wolfram Alpha/Module.config

148
Combot.Servers.Release.config

@ -0,0 +1,148 @@ @@ -0,0 +1,148 @@
[
{
"Name": "Rizon",
"Nicknames": [
"Combot",
"Combot_V3"
],
"Realname": "Combot",
"Username": "Combot",
"Password": "24121exe",
"Email": "admin@teknik.io",
"Owners": [
"Uncled1023"
],
"ChannelBlacklist": [
"#/g/iggle",
"#/g/tv",
"#supbro",
"#/fit/",
"#/x/files",
"#tuppers",
"#/g/hetto",
"#code"
],
"NickBlacklist": [
"KugelBlitz",
"ChanStat",
"NiNi",
"Kug|Pi",
"LoremIpsum",
"IRCBot",
"t4w|pi",
"Gurren",
"GEEEECraft",
"_KugelBlitz_",
"LoremIpsum",
"Kasuto",
"Kasuto|1",
"Tombot",
"Merzbot",
"bane",
"deskbot",
"spoonbot",
"Janice",
"STumbles",
"lykbot",
"beelzaboot"
],
"Hosts": [
{
"Host": "irc.rizon.net",
"Port": 6667
}
],
"Channels": [
{
"Name": "#/g/technology",
"Key": ""
},
{
"Name": "#tech-mod",
"Key": ""
},
{
"Name": "#/g/bots",
"Key": ""
},
{
"Name": "#toehoef",
"Key": ""
},
{
"Name": "#bots",
"Key": ""
},
{
"Name": "#Technocracy",
"Key": ""
},
{
"Name": "#Teknik",
"Key": ""
},
{
"Name": "#/g/entlemen",
"Key": ""
},
{
"Name": "#kitties",
"Key": ""
},
{
"Name": "#minimalrice",
"Key": ""
},
{
"Name": "#pentest",
"Key": ""
},
{
"Name": "#riceshop",
"Key": ""
},
{
"Name": "#/g/programming",
"Key": ""
},
{
"Name": "#jakarta",
"Key": ""
},
{
"Name": "#/g/trivia",
"Key": ""
},
{
"Name": "#tech",
"Key": ""
},
{
"Name": "#rice",
"Key": ""
},
{
"Name": "#india.suna",
"Key": ""
},
{
"Name": "#wheat",
"Key": ""
}
],
"Database": {
"Server": "192.168.11.40",
"Port": 3306,
"Database": "Combot",
"Username": "Combot",
"Password": "24121exe"
},
"ModuleLocation": "Modules",
"AutoConnect": true,
"AutoRegister": false,
"CommandPrefix": ".",
"JoinDelay": 100,
"MaxMessageLength": 400,
"MessageSendDelay": 100
}
]

27
Combot.sln

@ -9,6 +9,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Inte @@ -9,6 +9,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Inte
{D469C717-7625-40F1-966D-3C9DD00F5B9C} = {D469C717-7625-40F1-966D-3C9DD00F5B9C}
{EBAC601C-652C-466A-B4F0-94495F4C8E49} = {EBAC601C-652C-466A-B4F0-94495F4C8E49}
{289A0E25-F669-4E00-9DB9-0C5AE51E2BCC} = {289A0E25-F669-4E00-9DB9-0C5AE51E2BCC}
{9ADA4844-4566-4C2E-8649-3D87E2F76563} = {9ADA4844-4566-4C2E-8649-3D87E2F76563}
{72CCA645-3E1D-4355-9BDE-5C1884BCB6FC} = {72CCA645-3E1D-4355-9BDE-5C1884BCB6FC}
{1A544D51-1041-4A9A-B1ED-E738735DF52E} = {1A544D51-1041-4A9A-B1ED-E738735DF52E}
{2AD43A57-CDFF-4098-AC09-82159744C6E4} = {2AD43A57-CDFF-4098-AC09-82159744C6E4}
@ -16,7 +17,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Inte @@ -16,7 +17,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Inte
{18369F84-BD20-4946-B3D6-F2152148B2B4} = {18369F84-BD20-4946-B3D6-F2152148B2B4}
{60902085-CEF9-4C38-96F4-644F4574681F} = {60902085-CEF9-4C38-96F4-644F4574681F}
{6FEDA88B-70F0-4E7B-9079-C5530247F8AB} = {6FEDA88B-70F0-4E7B-9079-C5530247F8AB}
{909F6291-F0F5-4452-A4CA-BEF96916C01D} = {909F6291-F0F5-4452-A4CA-BEF96916C01D}
{A4D79B92-8D54-46BA-94AD-31CEA23E5688} = {A4D79B92-8D54-46BA-94AD-31CEA23E5688}
{2434E995-592F-4EE2-B321-033B7493F93E} = {2434E995-592F-4EE2-B321-033B7493F93E}
{516ECE98-0D6D-4713-AEDA-EDF47FFAA80B} = {516ECE98-0D6D-4713-AEDA-EDF47FFAA80B}
{EFAC8BA8-AF57-4D9C-9F00-1758FCC2F22E} = {EFAC8BA8-AF57-4D9C-9F00-1758FCC2F22E}
EndProjectSection
@ -61,6 +64,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Modules\Logging\ @@ -61,6 +64,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Modules\Logging\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Introductions", "Modules\Introductions\Introductions.csproj", "{6FEDA88B-70F0-4E7B-9079-C5530247F8AB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Quotes", "Modules\Quotes\Quotes.csproj", "{9ADA4844-4566-4C2E-8649-3D87E2F76563}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Seen", "Modules\Seen\Seen.csproj", "{909F6291-F0F5-4452-A4CA-BEF96916C01D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Messaging", "Modules\Messaging\Messaging.csproj", "{2434E995-592F-4EE2-B321-033B7493F93E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -135,6 +144,18 @@ Global @@ -135,6 +144,18 @@ Global
{6FEDA88B-70F0-4E7B-9079-C5530247F8AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FEDA88B-70F0-4E7B-9079-C5530247F8AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FEDA88B-70F0-4E7B-9079-C5530247F8AB}.Release|Any CPU.Build.0 = Release|Any CPU
{9ADA4844-4566-4C2E-8649-3D87E2F76563}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9ADA4844-4566-4C2E-8649-3D87E2F76563}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9ADA4844-4566-4C2E-8649-3D87E2F76563}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9ADA4844-4566-4C2E-8649-3D87E2F76563}.Release|Any CPU.Build.0 = Release|Any CPU
{909F6291-F0F5-4452-A4CA-BEF96916C01D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{909F6291-F0F5-4452-A4CA-BEF96916C01D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{909F6291-F0F5-4452-A4CA-BEF96916C01D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{909F6291-F0F5-4452-A4CA-BEF96916C01D}.Release|Any CPU.Build.0 = Release|Any CPU
{2434E995-592F-4EE2-B321-033B7493F93E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2434E995-592F-4EE2-B321-033B7493F93E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2434E995-592F-4EE2-B321-033B7493F93E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2434E995-592F-4EE2-B321-033B7493F93E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -154,8 +175,8 @@ Global @@ -154,8 +175,8 @@ Global
{516ECE98-0D6D-4713-AEDA-EDF47FFAA80B} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{289A0E25-F669-4E00-9DB9-0C5AE51E2BCC} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{6FEDA88B-70F0-4E7B-9079-C5530247F8AB} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
{9ADA4844-4566-4C2E-8649-3D87E2F76563} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{909F6291-F0F5-4452-A4CA-BEF96916C01D} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{2434E995-592F-4EE2-B321-033B7493F93E} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
EndGlobalSection
EndGlobal

5
Combot/Bot.cs

@ -211,6 +211,11 @@ namespace Combot @@ -211,6 +211,11 @@ namespace Combot
return hasAccess;
}
public void ExecuteCommand(string message, string location, MessageType type)
{
ParseCommandMessage(DateTime.Now, message, new Nick { Nickname = IRC.Nickname }, location, type);
}
private void HandleConnectEvent()
{
Connected = true;

26
Combot/Modules/Module.cs

@ -72,7 +72,7 @@ namespace Combot.Modules @@ -72,7 +72,7 @@ namespace Combot.Modules
{
nickAccessTypes.Add(Bot.PrivilegeModeMapping[privilege]);
}
if (Bot.ServerConfig.Owners.Contains(command.Nick.Nickname) && command.Nick.Modes.Contains(UserMode.r))
if ((Bot.ServerConfig.Owners.Contains(command.Nick.Nickname) && command.Nick.Modes.Contains(UserMode.r)) || command.Nick.Nickname == Bot.IRC.Nickname)
{
nickAccessTypes.Add(AccessType.Owner);
}
@ -247,8 +247,9 @@ namespace Combot.Modules @@ -247,8 +247,9 @@ namespace Combot.Modules
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT * FROM `channels` WHERE " +
"`name` = {0}";
List<Dictionary<string, object>> results = database.Query(search, new object[] { channel });
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}) AND " +
"`name` = {1}";
List<Dictionary<string, object>> results = database.Query(search, new object[] { Bot.ServerConfig.Name, channel });
if (!results.Any())
{
@ -263,8 +264,9 @@ namespace Combot.Modules @@ -263,8 +264,9 @@ namespace Combot.Modules
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT * FROM `nicks` WHERE " +
"`nickname` = {0}";
List<Dictionary<string, object>> results = database.Query(search, new object[] { nickname });
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}) AND " +
"`nickname` = {1}";
List<Dictionary<string, object>> results = database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
if (!results.Any())
{
@ -274,5 +276,19 @@ namespace Combot.Modules @@ -274,5 +276,19 @@ namespace Combot.Modules
database.Execute(insert, new object[] { Bot.ServerConfig.Name, nickname });
}
}
public string GetNickname(int id)
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT `nickname` FROM `nicks` " +
"WHERE `id` = {0}";
List<Dictionary<string, object>> results = database.Query(search, new object[] { id });
string nickname = string.Empty;
if (results.Any())
{
nickname = results.First()["nickname"].ToString();
}
return nickname;
}
}
}

7
IRCServices/IRC.cs

@ -342,7 +342,12 @@ namespace Combot.IRCServices @@ -342,7 +342,12 @@ namespace Combot.IRCServices
}
else
{
nick.Modes.Add((UserMode)Enum.Parse(typeof(UserMode), modeArr[i].ToString()));
UserMode foundMode;
bool valid = Enum.TryParse(modeArr[i].ToString(), false, out foundMode);
if (valid)
{
nick.Modes.Add(foundMode);
}
}
}
if (!nickFound)

80
IRCServices/SendCommand.cs

@ -21,34 +21,30 @@ namespace Combot.IRCServices @@ -21,34 +21,30 @@ namespace Combot.IRCServices
if (sinceLastMessage.TotalMilliseconds < MessageSendDelay)
{
Thread.Sleep((int) sinceLastMessage.TotalMilliseconds);
SendPrivateMessage(recipient, message);
}
else
LastMessageSend = DateTime.Now;
if (message.Length > MaxMessageLength)
{
LastMessageSend = DateTime.Now;
if (message.Length > MaxMessageLength)
List<string> splitMessage = message.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries).ToList();
string subMessage = string.Empty;
string nextMessage = string.Empty;
for (int i = 0; i < splitMessage.Count; i++)
{
List<string> splitMessage = message.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries).ToList();
string subMessage = string.Empty;
string nextMessage = string.Empty;
for (int i = 0; i < splitMessage.Count; i++)
int wordLength = splitMessage[i].Length + 1;
int totalLength = subMessage.Length;
if (totalLength + wordLength > MaxMessageLength)
{
int wordLength = splitMessage[i].Length + 1;
int totalLength = subMessage.Length;
if (totalLength + wordLength > MaxMessageLength)
{
nextMessage = string.Join(" ", splitMessage.GetRange(i, splitMessage.Count - i));
break;
}
subMessage = string.Join(" ", subMessage, splitMessage[i]);
nextMessage = string.Join(" ", splitMessage.GetRange(i, splitMessage.Count - i));
break;
}
SendTCPMessage(string.Format("PRIVMSG {0} :{1}", recipient, subMessage));
SendPrivateMessage(recipient, nextMessage);
}
else
{
SendTCPMessage(string.Format("PRIVMSG {0} :{1}", recipient, message));
subMessage = string.Join(" ", subMessage, splitMessage[i]);
}
SendTCPMessage(string.Format("PRIVMSG {0} :{1}", recipient, subMessage));
SendPrivateMessage(recipient, nextMessage);
}
else
{
SendTCPMessage(string.Format("PRIVMSG {0} :{1}", recipient, message));
}
}
@ -73,34 +69,30 @@ namespace Combot.IRCServices @@ -73,34 +69,30 @@ namespace Combot.IRCServices
if (sinceLastMessage.TotalMilliseconds < MessageSendDelay)
{
Thread.Sleep((int) sinceLastMessage.TotalMilliseconds);
SendNotice(recipient, message);
}
else
LastMessageSend = DateTime.Now;
if (message.Length > MaxMessageLength)
{
LastMessageSend = DateTime.Now;
if (message.Length > MaxMessageLength)
List<string> splitMessage = message.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries).ToList();
string subMessage = string.Empty;
string nextMessage = string.Empty;
for (int i = 0; i < splitMessage.Count; i++)
{
List<string> splitMessage = message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
string subMessage = string.Empty;
string nextMessage = string.Empty;
for (int i = 0; i < splitMessage.Count; i++)
int wordLength = splitMessage[i].Length + 1;
int totalLength = subMessage.Length;
if (totalLength + wordLength > MaxMessageLength)
{
int wordLength = splitMessage[i].Length + 1;
int totalLength = subMessage.Length;
if (totalLength + wordLength > MaxMessageLength)
{
nextMessage = string.Join(" ", splitMessage.GetRange(i, splitMessage.Count - i));
break;
}
subMessage = string.Join(" ", subMessage, splitMessage[i]);
nextMessage = string.Join(" ", splitMessage.GetRange(i, splitMessage.Count - i));
break;
}
SendTCPMessage(string.Format("NOTICE {0} :{1}", recipient, subMessage));
SendNotice(recipient, nextMessage);
}
else
{
SendTCPMessage(string.Format("NOTICE {0} :{1}", recipient, message));
subMessage = string.Join(" ", subMessage, splitMessage[i]);
}
SendTCPMessage(string.Format("NOTICE {0} :{1}", recipient, subMessage));
SendNotice(recipient, nextMessage);
}
else
{
SendTCPMessage(string.Format("NOTICE {0} :{1}", recipient, message));
}
}

23
Interface/BufferInfo.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
using System.Collections.Generic;
namespace Interface
{
public class BufferInfo
{
public string Server { get; set; }
public string Location { get; set; }
public List<string> Buffer { get; set; }
public BufferInfo()
{
SetDefaults();
}
public void SetDefaults()
{
Server = string.Empty;
Location = string.Empty;
Buffer = new List<string>();
}
}
}

1
Interface/Interface.csproj

@ -69,6 +69,7 @@ @@ -69,6 +69,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="BufferInfo.cs" />
<Compile Include="ViewModels\MainViewModel.cs" />
<Compile Include="ViewModels\ViewModelBase.cs" />
<Page Include="MainWindow.xaml">

25
Interface/MainWindow.xaml

@ -3,9 +3,26 @@ @@ -3,9 +3,26 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Interface"
xmlns:prop="clr-namespace:Interface.Properties"
Title="{Binding ApplicationTitle, Mode=TwoWay}" Height="350" Width="525">
<Grid>
<Button x:Name="ToggleConnectionButton" Content="{Binding ToggleConnectionText}" HorizontalAlignment="Left" Margin="10,0,0,10" Width="156" Command="{Binding ToggleConnection}" Height="33" VerticalAlignment="Bottom"/>
<TextBox x:Name="BufferWindow" Margin="10,10,10,48" TextWrapping="Wrap" Text="{Binding CurrentBuffer, Mode=TwoWay}"/>
xmlns:view="clr-namespace:Interface.ViewModels"
Title="{Binding ApplicationTitle, Mode=TwoWay}" Height="372" Width="850" ResizeMode="CanResizeWithGrip">
<Grid Margin="0,0,0,2">
<Button x:Name="ToggleConnectionButton" Content="{Binding ToggleConnectionText}" Margin="10,0,0,10" Command="{Binding ToggleConnection}" Height="23" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="100"/>
<ComboBox x:Name="ServerListBox" ItemsSource="{Binding ServerList, Mode=TwoWay}" SelectedItem="{Binding SelectedServer, Mode=TwoWay}" Height="25" Margin="0,10,10,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="114"/>
<ListBox x:Name="LocationListBox" ItemsSource="{Binding LocationList, Mode=TwoWay}" SelectedItem="{Binding SelectedLocation, Mode=TwoWay}" HorizontalAlignment="Right" Margin="0,40,10,38" Width="114"/>
<TextBox x:Name="InputBox" Text="{Binding InputBoxText, UpdateSourceTrigger=PropertyChanged}" Margin="115,0,129,10" TextWrapping="Wrap" Height="23" VerticalAlignment="Bottom" AcceptsReturn="True">
<TextBox.InputBindings>
<KeyBinding Command="{Binding SubmitText}" Key="Enter"/>
</TextBox.InputBindings>
</TextBox>
<Button x:Name="SubmitButton" Content="Submit" Command="{Binding SubmitText}" Margin="0,0,10,10" HorizontalAlignment="Right" Width="114" Height="23" VerticalAlignment="Bottom"/>
<RichTextBox x:Name="BufferWindow" Margin="10,10,129,38" VerticalScrollBarVisibility="Auto" IsReadOnly="True">
<FlowDocument>
<Paragraph>
<Run Text="{Binding CurrentBuffer, Mode=TwoWay}"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</Grid>
</Window>

306
Interface/ViewModels/MainViewModel.cs

@ -1,13 +1,16 @@ @@ -1,13 +1,16 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Runtime.Remoting.Channels;
using System.Windows.Documents;
using Combot;
using Combot.IRCServices.Messaging;
using Combot.Configurations;
using Combot.Modules;
namespace Interface.ViewModels
{
@ -19,103 +22,231 @@ namespace Interface.ViewModels @@ -19,103 +22,231 @@ namespace Interface.ViewModels
public string ApplicationTitle { get; set; }
private string _CurrentBuffer = string.Empty;
public string CurrentBuffer { get { return _CurrentBuffer; } set { _CurrentBuffer = value; OnPropertyChanged("CurrentBuffer"); } }
public string CurrentBuffer
{
get { return _CurrentBuffer; }
set
{
_CurrentBuffer = value;
OnPropertyChanged("CurrentBuffer");
}
}
private bool _Connected = false;
public bool Connected { get { return _Connected; } set { _Connected = value; if (_Connected) { ToggleConnectionText = "Disconnect"; } else { ToggleConnectionText = "Connect"; } OnPropertyChanged("Connected"); } }
public bool Connected
{
get { return _Connected; }
set
{
_Connected = value;
if (_Connected)
{
ToggleConnectionText = "Disconnect";
}
else
{
ToggleConnectionText = "Connect";
}
OnPropertyChanged("Connected");
}
}
private string _ToggleConnectionText = "Connect";
public string ToggleConnectionText { get { return _ToggleConnectionText; } set { _ToggleConnectionText = value; OnPropertyChanged("ToggleConnectionText"); } }
public string ToggleConnectionText
{
get { return _ToggleConnectionText; }
set
{
_ToggleConnectionText = value;
OnPropertyChanged("ToggleConnectionText");
}
}
private string _InputBoxText;
public string InputBoxText
{
get { return _InputBoxText; }
set
{
_InputBoxText = value;
OnPropertyChanged("InputBoxText");
}
}
private string _SelectedServer;
public string SelectedServer
{
get { return _SelectedServer; }
set
{
_SelectedServer = value;
OnPropertyChanged("SelectedServer");
ChangeServer();
ChangeBuffer();
}
}
private string _SelectedLocation;
public string SelectedLocation
{
get { return _SelectedLocation; }
set
{
_SelectedLocation = value;
OnPropertyChanged("SelectedLocation");
ChangeBuffer();
}
}
private ObservableCollection<string> _ServerList;
public ObservableCollection<string> ServerList
{
get { return _ServerList; }
set
{
if (_ServerList != value)
{
_ServerList = value;
OnPropertyChanged("ServerList");
}
}
}
private ObservableCollection<string> _LocationList;
public ObservableCollection<string> LocationList
{
get { return _LocationList; }
set
{
if (_LocationList != value)
{
_LocationList = value;
OnPropertyChanged("LocationList");
}
}
}
public DelegateCommand ToggleConnection { get; private set; }
public DelegateCommand SubmitText { get; set; }
private List<BufferInfo> BufferList = new List<BufferInfo>();
public MainViewModel()
{
ApplicationTitle = "Combot";
Config.LoadServers();
ServerList = new ObservableCollection<string>();
LocationList = new ObservableCollection<string>();
foreach (ServerConfig server in Config.Servers)
{
ServerList.Add(server.Name);
Bot Combot = new Bot(server);
/*
Combot.IRC.Message.ErrorMessageEvent += ErrorMessageHandler;
Combot.IRC.Message.ServerReplyEvent += ServerReplyHandler;
Combot.IRC.Message.ChannelMessageReceivedEvent += ChannelMessageReceivedHandler;
Combot.IRC.Message.ChannelNoticeReceivedEvent += ChannelNoticeReceivedHandler;
Combot.IRC.Message.PrivateMessageReceivedEvent += PrivateMessageReceivedHandler;
Combot.IRC.Message.PrivateNoticeReceivedEvent += PrivateNoticeReceivedHandler;
*/
Combot.IRC.Message.RawMessageEvent += RawMessageHandler;
Combot.IRC.ConnectEvent += ConnectHandler;
Combot.IRC.DisconnectEvent += DisconnectHandler;
Combot.IRC.TCPErrorEvent += TCPErrorHandler;
Combot.IRC.Message.ErrorMessageEvent += (sender, e) => ErrorMessageHandler(sender, e, server.Name);
Combot.IRC.Message.ServerReplyEvent += (sender, e) => ServerReplyHandler(sender, e, server.Name);
Combot.IRC.Message.ChannelMessageReceivedEvent += (sender, e) => ChannelMessageReceivedHandler(sender, e, server.Name);
Combot.IRC.Message.ChannelNoticeReceivedEvent += (sender, e) => ChannelNoticeReceivedHandler(sender, e, server.Name);
Combot.IRC.Message.PrivateMessageReceivedEvent += (sender, e) => PrivateMessageReceivedHandler(sender, e, server.Name);
Combot.IRC.Message.PrivateNoticeReceivedEvent += (sender, e) => PrivateNoticeReceivedHandler(sender, e, server.Name);
//Combot.IRC.Message.RawMessageEvent += RawMessageHandler;
Combot.IRC.Message.JoinChannelEvent += (sender, e) => JoinEventHandler(sender, e, server.Name);
Combot.IRC.ConnectEvent += () => ConnectHandler(server.Name);
Combot.IRC.DisconnectEvent += () => DisconnectHandler(server.Name);
Combot.IRC.TCPErrorEvent += e => TCPErrorHandler(e, server.Name);
CombotSessions.Add(Combot);
SelectedServer = server.Name;
if (server.AutoConnect)
{
Combot.Connect();
}
}
ToggleConnection = new DelegateCommand(ExecuteToggleConnection, CanToggleConnection);
SubmitText = new DelegateCommand(ExecuteSubmitText, CanSubmitText);
}
private void JoinEventHandler(object sender, JoinChannelInfo info, string server)
{
AddToBuffer(server, info.Channel, string.Format("{0} has joined {1}.", info.Nick.Nickname, info.Channel));
}
private void RawMessageHandler(object sender, string message)
{
CurrentBuffer += message + Environment.NewLine;
//CurrentBuffer += message + Environment.NewLine;
}
private void TCPErrorHandler(Combot.IRCServices.TCP.TCPError error)
private void TCPErrorHandler(Combot.IRCServices.TCP.TCPError error, string server)
{
CurrentBuffer += string.Format("[{0}] {1}", error.Code.ToString(), error.Message) + Environment.NewLine;
AddToBuffer(server, null, string.Format("[{0}] {1}", error.Code.ToString(), error.Message));
}
private void ServerReplyHandler(object sender, IReply reply)
private void ServerReplyHandler(object sender, IReply reply, string server)
{
CurrentBuffer += reply.Message + Environment.NewLine;
AddToBuffer(server, null, reply.Message);
}
private void ErrorMessageHandler(object sender, ErrorMessage message)
private void ErrorMessageHandler(object sender, ErrorMessage message, string server)
{
CurrentBuffer += message.Message + Environment.NewLine;
AddToBuffer(server, null, message.Message);
}
private void ChannelMessageReceivedHandler(object sender, ChannelMessage message)
private void ChannelMessageReceivedHandler(object sender, ChannelMessage message, string server)
{
CurrentBuffer += message.Message + Environment.NewLine;
AddToBuffer(server, message.Channel, message.Message);
}
private void ChannelNoticeReceivedHandler(object sender, ChannelNotice message)
private void ChannelNoticeReceivedHandler(object sender, ChannelNotice message, string server)
{
CurrentBuffer += message.Message + Environment.NewLine;
AddToBuffer(server, message.Channel, message.Message);
}
private void PrivateMessageReceivedHandler(object sender, PrivateMessage message)
private void PrivateMessageReceivedHandler(object sender, PrivateMessage message, string server)
{
CurrentBuffer += message.Message + Environment.NewLine;
AddToBuffer(server, message.Sender.Nickname, message.Message);
}
private void PrivateNoticeReceivedHandler(object sender, PrivateNotice message)
private void PrivateNoticeReceivedHandler(object sender, PrivateNotice message, string server)
{
CurrentBuffer += message.Message + Environment.NewLine;
AddToBuffer(server, message.Sender.Nickname, message.Message);
}
private void ConnectHandler()
private void ConnectHandler(string server)
{
Connected = true;
if (server == SelectedServer)
{
Connected = true;
}
}
private void DisconnectHandler()
private void DisconnectHandler(string server)
{
Connected = false;
if (server == SelectedServer)
{
Connected = false;
}
}
private void ExecuteToggleConnection()
{
if (_Connected)
{
Disconnect();
Disconnect(SelectedServer);
}
else
{
Connect();
Connect(SelectedServer);
}
}
@ -124,14 +255,105 @@ namespace Interface.ViewModels @@ -124,14 +255,105 @@ namespace Interface.ViewModels
return true;
}
private void Connect()
private void ExecuteSubmitText()
{
if (SelectedLocation != " --Server-- ")
{
Bot botInstance = CombotSessions.Find(bot => bot.ServerConfig.Name == SelectedServer);
if (botInstance != null && botInstance.Connected)
{
string message = InputBoxText;
if (InputBoxText.StartsWith("/"))
{
MessageType type = MessageType.Query;
if (SelectedLocation.StartsWith("#") || SelectedLocation.StartsWith("&"))
{
type = MessageType.Channel;
}
message = message.Remove(0, 1);
message = string.Join("", botInstance.ServerConfig.CommandPrefix, message);
botInstance.ExecuteCommand(message, SelectedLocation, type);
}
else
{
botInstance.IRC.SendPrivateMessage(SelectedLocation, message);
}
InputBoxText = string.Empty;
}
}
}
private bool CanSubmitText()
{
return true;
}
private void Connect(string server)
{
CombotSessions.Find(bot => bot.ServerConfig.Name == server).Connect();
}
private void Disconnect(string server)
{
CombotSessions.Find(bot => bot.ServerConfig.Name == server).Disconnect();
}
private void AddToBuffer(string server, string location, string message)
{
if (location == null)
{
location = " --Server-- ";
}
if (!BufferList.Exists(buf => buf.Server == server && buf.Location == location))
{
BufferInfo newBuffer = new BufferInfo();
newBuffer.Server = server;
newBuffer.Location = location;
BufferList.Add(newBuffer);
}
if (SelectedServer == server && !LocationList.Contains(location))
{
App.Current.Dispatcher.Invoke((Action) (() => LocationList.Add(location)));
}
BufferInfo buffer = BufferList.Find(buf => buf.Server == server && buf.Location == location);
if (buffer.Buffer.Count >= 1000)
{
buffer.Buffer.RemoveAt(0);
}
buffer.Buffer.Add(message);
ChangeBuffer();
}
private void ChangeServer()
{
CombotSessions.ForEach(Combot => Combot.Connect());
App.Current.Dispatcher.Invoke((Action)(() => LocationList.Clear()));
for (int i = 0; i < BufferList.Count; i++)
{
if (BufferList[i].Server == SelectedServer)
{
App.Current.Dispatcher.Invoke((Action)(() => LocationList.Add(BufferList[i].Location)));
}
}
if (LocationList.Any())
{
SelectedLocation = LocationList.First();
}
}
private void Disconnect()
private void ChangeBuffer()
{
CombotSessions.ForEach(Combot => Combot.Disconnect());
if (SelectedServer != null && SelectedLocation != null)
{
if (!BufferList.Exists(buf => buf.Server == SelectedServer && buf.Location == SelectedLocation))
{
BufferInfo newBuffer = new BufferInfo();
newBuffer.Server = SelectedServer;
newBuffer.Location = SelectedLocation;
BufferList.Add(newBuffer);
}
CurrentBuffer = string.Join(Environment.NewLine, BufferList.Find(buf => buf.Server == SelectedServer && buf.Location == SelectedLocation).Buffer);
Connected = CombotSessions.Find(bot => bot.ServerConfig.Name == SelectedServer).Connected;
}
}
}
}

53
Modules/Help/Help.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
namespace Combot.Modules.Plugins
{
@ -30,7 +31,7 @@ namespace Combot.Modules.Plugins @@ -30,7 +31,7 @@ namespace Combot.Modules.Plugins
private void SendFullHelp(string recipient, List<AccessType> access)
{
Bot.IRC.SendNotice(recipient, string.Format("You have the following commands available to use. " +
"To use them either type \u0002{1}\u001Fcommand trigger\u000F into a channel, send a private message by typing \u0002/msg {0} \u001Fcommand trigger\u000F, or send a notice by typing \u0002/notice {0} \u001Fcommand trigger\u000F. ",
"To use them either type \u0002{1}\u001Fcommand trigger\u001F\u0002 into a channel, send a private message by typing \u0002/msg {0} \u001Fcommand trigger\u001F\u0002, or send a notice by typing \u0002/notice {0} \u001Fcommand trigger\u001F\u0002. ",
Bot.IRC.Nickname, Bot.ServerConfig.CommandPrefix));
Bot.IRC.SendNotice(recipient, "\u200B");
List<string> commandList = new List<string>();
@ -44,9 +45,9 @@ namespace Combot.Modules.Plugins @@ -44,9 +45,9 @@ namespace Combot.Modules.Plugins
}
});
}
Bot.IRC.SendNotice(recipient, string.Format("\u0002{0}\u000F", string.Join("\u000F, \u0002", commandList)));
Bot.IRC.SendNotice(recipient, string.Format("\u0002{0}\u0002", string.Join("\u0002, \u0002", commandList)));
Bot.IRC.SendNotice(recipient, "\u200B");
Bot.IRC.SendNotice(recipient, string.Format("For more information on a specific command, including viewing the triggers, type \u0002{0}help \u001Fcommand\u000F.", Bot.ServerConfig.CommandPrefix));
Bot.IRC.SendNotice(recipient, string.Format("For more information on a specific command, including viewing the triggers, type \u0002{0}help \u001Fcommand\u001F\u0002.", Bot.ServerConfig.CommandPrefix));
}
private void SendCommandHelp(CommandMessage command)
@ -60,7 +61,7 @@ namespace Combot.Modules.Plugins @@ -60,7 +61,7 @@ namespace Combot.Modules.Plugins
{
if (foundCommand.AllowedAccess.Exists(allowed => command.Access.Contains(allowed)))
{
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("Help information for \u0002{0}\u000F", foundCommand.Name));
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("Help information for \u0002{0}\u0002", foundCommand.Name));
if (foundCommand.Description != string.Empty)
{
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("{0}", foundCommand.Description));
@ -75,32 +76,45 @@ namespace Combot.Modules.Plugins @@ -75,32 +76,45 @@ namespace Combot.Modules.Plugins
switch (messageType)
{
case MessageType.Channel:
messageSyntax = "\u0002/msg \u001Fchannel\u000F";
messageSyntax = "\u0002/msg \u001Fchannel\u001F\u0002";
break;
case MessageType.Query:
messageSyntax = string.Format("\u0002/msg {0}\u000F", Bot.IRC.Nickname);
messageSyntax = string.Format("\u0002/msg {0}\u0002", Bot.IRC.Nickname);
break;
case MessageType.Notice:
messageSyntax = string.Format("\u0002/notice {0}\u000F", Bot.IRC.Nickname);
messageSyntax = string.Format("\u0002/notice {0}\u0002", Bot.IRC.Nickname);
break;
}
List<CommandArgument> validArguments = foundCommand.Arguments.FindAll(arg => arg.MessageTypes.Contains(messageType));
string argHelp = string.Empty;
if (validArguments.Count > 0)
{
argHelp = string.Format(" \u0002{0}\u000F", string.Join(" ", validArguments.Select(arg =>
argHelp = string.Format(" \u0002{0}\u0002", string.Join(" ", validArguments.Select(arg =>
{
string argString = string.Empty;
if (arg.DependentArguments.Count > 0)
{
argString = "(";
}
if (arg.Required)
{
return "\u001F" + arg.Name + "\u000F\u0002";
argString += "\u001F" + arg.Name + "\u001F";
}
return "[\u001F" + arg.Name + "\u000F\u0002]";
else
{
argString += "[\u001F" + arg.Name + "\u001F]";
}
if (arg.DependentArguments.Count > 0)
{
argString += string.Format("\u0002:When {0}\u0002)", string.Join(" or ", arg.DependentArguments.Select(dep => { return string.Format("\u0002\u001F{0}\u001F\u0002=\u0002{1}\u0002", dep.Name, string.Join(",", dep.Values)); })));
}
return argString;
})));
}
if (foundCommand.Triggers.Any())
{
string triggerString = (foundCommand.Triggers.Count > 1) ? string.Format("({0})", string.Join("|", foundCommand.Triggers)) : foundCommand.Triggers.First();
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("Syntax: {0} {1}\u0002{2}\u000F{3}", messageSyntax, Bot.ServerConfig.CommandPrefix, triggerString, argHelp));
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("Syntax: {0} {1}\u0002{2}\u0002{3}", messageSyntax, Bot.ServerConfig.CommandPrefix, triggerString, argHelp));
}
// Display argument help
@ -113,17 +127,10 @@ namespace Combot.Modules.Plugins @@ -113,17 +127,10 @@ namespace Combot.Modules.Plugins
{
commandDesc = string.Format(" - {0}", arg.Description);
}
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("\t\t\u0002{0}\u000F{1}", arg.Name, commandDesc));
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("\t\t\u0002{0}\u0002{1}", arg.Name, commandDesc));
if (arg.AllowedValues.Count > 0)
{
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("\t\t\t\tAllowed Values: \u0002{0}\u000F", string.Join(", ", arg.AllowedValues)));
}
if (arg.DependentArguments.Count > 0)
{
foreach (CommandArgument.DependentArgumentInfo dependentArgument in arg.DependentArguments)
{
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("\t\t\t\tOnly used when \u0002{0}\u000F is \u0002{1}\u000F.", dependentArgument.Name, string.Join(", or ", dependentArgument.Values)));
}
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("\t\t\t\tAllowed Values: \u0002{0}\u0002", string.Join(", ", arg.AllowedValues)));
}
});
}
@ -131,17 +138,17 @@ namespace Combot.Modules.Plugins @@ -131,17 +138,17 @@ namespace Combot.Modules.Plugins
}
else
{
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("You do not have access to view help on \u0002{0}\u000F.", helpCommand));
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("You do not have access to view help on \u0002{0}\u0002.", helpCommand));
}
}
else
{
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("The command \u0002{0}\u000F does not exist.", helpCommand));
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("The command \u0002{0}\u0002 does not exist.", helpCommand));
}
}
else
{
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("The command \u0002{0}\u000F does not exist.", helpCommand));
Bot.IRC.SendNotice(command.Nick.Nickname, string.Format("The command \u0002{0}\u0002 does not exist.", helpCommand));
}
}
}

262
Modules/Introductions/Introductions.cs

@ -27,10 +27,13 @@ namespace Combot.Modules.Plugins @@ -27,10 +27,13 @@ namespace Combot.Modules.Plugins
AddIntroduction(command);
break;
case "edit":
EditIntroduction(command);
break;
case "delete":
DeleteIntroduction(command);
break;
case "view":
ViewIntroduction(command);
break;
}
break;
@ -39,36 +42,46 @@ namespace Combot.Modules.Plugins @@ -39,36 +42,46 @@ namespace Combot.Modules.Plugins
private void HandleJoinEvent(object sender, JoinChannelInfo info)
{
List<Dictionary<string, object>> results = GetIntroductionList(info.Channel, info.Nick.Nickname);
if (results.Any())
{
Random randNum = new Random();
int index = randNum.Next(results.Count - 1);
Dictionary<string, object> intro = results[index];
Bot.IRC.SendPrivateMessage(info.Channel, string.Format("\u200B{0}", intro["message"]));
}
}
private void AddIntroduction(CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
Database database = new Database(Bot.ServerConfig.Database);
// Check to see if they have reached the max number of introductions
string search = "SELECT `introductions`.`id` FROM `introductions` INNER JOIN `nicks` " +
"ON `introductions`.`nick_id` = `nicks`.`id` " +
"INNER JOIN `channels` " +
"ON `introductions`.`channel_id` = `channels`.`id` " +
"INNER JOIN `servers` " +
"ON `nicks`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} AND `nicks`.`nickname` = {2}";
List<Dictionary<string, object>> results = database.Query(search, new object[] { Bot.ServerConfig.Name, channel, command.Nick.Nickname });
List<Dictionary<string, object>> results = GetIntroductionList(channel, command.Nick.Nickname);
if (results.Count < Convert.ToInt32(GetOptionValue("Max Introductions")))
{
AddChannel(channel);
AddNick(command.Nick.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `introductions` SET " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
"`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
"`message` = {5}, " +
"`date_added` = {6}";
database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, channel, Bot.ServerConfig.Name, command.Nick.Nickname, command.Arguments["Message"], command.TimeStamp});
database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, channel, Bot.ServerConfig.Name, command.Nick.Nickname, command.Arguments["Message"], command.TimeStamp });
string introMessage = string.Format("Added introduction. You now have \u0002{0}\u0002 introductions set.", results.Count + 1);
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(command.Location, introMessage);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, introMessage);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, introMessage);
break;
}
}
else
{
@ -87,5 +100,226 @@ namespace Combot.Modules.Plugins @@ -87,5 +100,226 @@ namespace Combot.Modules.Plugins
}
}
}
private void EditIntroduction(CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
List<Dictionary<string, object>> results = GetIntroductionList(channel, command.Nick.Nickname);
int num = 0;
if (int.TryParse(command.Arguments["ID"], out num))
{
if (results.Count >= num)
{
int id = Convert.ToInt32(results[num - 1]["id"]);
Database database = new Database(Bot.ServerConfig.Database);
string query = "UPDATE `introductions` SET " +
"`message` = {0} " +
"WHERE `id` = {1}";
database.Execute(query, new object[] { command.Arguments["Message"], id });
string introMessage = string.Format("Introduction #\u0002{0}\u0002 is now: {1}", num, command.Arguments["Message"]);
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(command.Location, introMessage);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, introMessage);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, introMessage);
break;
}
}
else
{
string invalid = "Invalid introduction ID.";
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(command.Location, invalid);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, invalid);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, invalid);
break;
}
}
}
else
{
string invalid = "Invalid introduction ID.";
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(command.Location, invalid);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, invalid);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, invalid);
break;
}
}
}
private void DeleteIntroduction(CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
List<Dictionary<string, object>> results = GetIntroductionList(channel, command.Nick.Nickname);
int num = 0;
if (int.TryParse(command.Arguments["ID"], out num))
{
if (results.Count >= num)
{
int id = Convert.ToInt32(results[num - 1]["id"]);
Database database = new Database(Bot.ServerConfig.Database);
string query = "DELETE FROM `introductions` " +
"WHERE `id` = {0}";
database.Execute(query, new object[] { id });
string introMessage = string.Format("Introduction #\u0002{0}\u0002 has been deleted.", num);
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(command.Location, introMessage);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, introMessage);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, introMessage);
break;
}
}
else
{
string invalid = "Invalid introduction ID.";
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(command.Location, invalid);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, invalid);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, invalid);
break;
}
}
}
else
{
string invalid = "Invalid introduction ID.";
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(command.Location, invalid);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, invalid);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, invalid);
break;
}
}
}
private void ViewIntroduction(CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
List<Dictionary<string, object>> results = GetIntroductionList(channel, command.Nick.Nickname);
int num = 0;
if (command.Arguments.ContainsKey("ID"))
{
if (int.TryParse(command.Arguments["ID"], out num))
{
if (results.Count >= num)
{
string introMessage = string.Format("Introduction #\u0002{0}\u0002: {1}", num, results[num - 1]["message"]);
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(command.Location, introMessage);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, introMessage);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, introMessage);
break;
}
}
else
{
string invalid = "Invalid introduction ID.";
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(command.Location, invalid);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, invalid);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, invalid);
break;
}
}
}
else
{
string invalid = "Invalid introduction ID.";
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(command.Location, invalid);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, invalid);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, invalid);
break;
}
}
}
else
{
for (int i = 0; i < results.Count; i++)
{
string introMessage = string.Format("Introduction #\u0002{0}\u0002: {1}", i + 1, results[i]["message"]);
switch (command.MessageType)
{
case MessageType.Channel:
Bot.IRC.SendNotice(command.Nick.Nickname, introMessage);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(command.Nick.Nickname, introMessage);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(command.Nick.Nickname, introMessage);
break;
}
}
}
}
private List<Dictionary<string, object>> GetIntroductionList(string channel, string nickname)
{
Database database = new Database(Bot.ServerConfig.Database);
// Check to see if they have reached the max number of introductions
string search = "SELECT `introductions`.`id`, `introductions`.`message` FROM `introductions` INNER JOIN `nicks` " +
"ON `introductions`.`nick_id` = `nicks`.`id` " +
"INNER JOIN `channels` " +
"ON `introductions`.`channel_id` = `channels`.`id` " +
"INNER JOIN `servers` " +
"ON `nicks`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} AND `nicks`.`nickname` = {2}";
return database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
}
}
}

6
Modules/Introductions/Module.config

@ -108,6 +108,12 @@ @@ -108,6 +108,12 @@
2
],
"AllowedAccess": [
0,
1,
2,
3,
4,
5,
6
],
"ShowHelp": true,

8
Modules/Logging/Logging.cs

@ -26,6 +26,7 @@ namespace Combot.Modules.Plugins @@ -26,6 +26,7 @@ namespace Combot.Modules.Plugins
private void LogChannelMessage(object sender, ChannelMessage message)
{
AddChannel(message.Channel);
AddNick(message.Sender.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `channelmessages` SET " +
@ -51,10 +52,7 @@ namespace Combot.Modules.Plugins @@ -51,10 +52,7 @@ namespace Combot.Modules.Plugins
private void LogChannelJoin(object sender, JoinChannelInfo info)
{
if (info.Nick.Nickname == Bot.IRC.Nickname)
{
AddChannel(info.Channel);
}
AddChannel(info.Channel);
AddNick(info.Nick.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `channeljoins` SET " +
@ -67,6 +65,7 @@ namespace Combot.Modules.Plugins @@ -67,6 +65,7 @@ namespace Combot.Modules.Plugins
private void LogChannelPart(object sender, PartChannelInfo info)
{
AddChannel(info.Channel);
AddNick(info.Nick.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `channelparts` SET " +
@ -79,6 +78,7 @@ namespace Combot.Modules.Plugins @@ -79,6 +78,7 @@ namespace Combot.Modules.Plugins
private void LogChannelKick(object sender, KickInfo info)
{
AddChannel(info.Channel);
AddNick(info.Nick.Nickname);
AddNick(info.KickedNick.Nickname);
Database database = new Database(Bot.ServerConfig.Database);

1
Modules/Logging/Logging.csproj

@ -56,6 +56,7 @@ @@ -56,6 +56,7 @@
<ItemGroup>
<None Include="Module.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

161
Modules/Messaging/Messaging.cs

@ -0,0 +1,161 @@ @@ -0,0 +1,161 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Combot.Databases;
using Combot.IRCServices.Messaging;
namespace Combot.Modules.Plugins
{