Пример #1
0
        public void ExecuteRuntime() {
            string data = ListenToStream();

            if (string.IsNullOrEmpty(data)) return;

            ChannelMessageEventArgs message = new ChannelMessageEventArgs(data);

            Writer.Log(message.Type.Equals(Protocols.PRIVMSG) ?
                $"<{message.Recipient} {message.Nickname}> {message.Args}" :
                data, EventLogEntryType.Information);

            if (message.Type == Protocols.ABORT) return;

            Channels.Add(message.Recipient);

            CheckCreateUser(message);
            UpdateCurrentUser(message.Realname);

            Users.LastSeen.UpdateUser(message.Nickname);

            Wrapper.PluginHost.TriggerChannelMessageCallback(this, message);
        }
Пример #2
0
 public void TriggerChannelMessageCallback(object source, ChannelMessageEventArgs e) {
     ChannelMessageCallback?.Invoke(this, e);
 }
Пример #3
0
        public void CheckCreateUser(ChannelMessageEventArgs message) {
            if (Users.Get(message.Realname) != null ||
                !message.IsRealUser) return;

            Users.Create(3, message.Nickname, message.Realname, message.Timestamp, true);
        }
Пример #4
0
		public void OnChannelMessage(object source, ChannelMessageEventArgs e) {
			Status = PluginStatus.Processing;

			Console.WriteLine(Program.Bot.Users.GetAll().First().Realname);

			PluginEventArgs responseEvent = new PluginEventArgs {
				MessageType = PluginEventMessageType.Message
			};

			PluginReturnMessage response = new PluginReturnMessage(Protocols.PRIVMSG, e.Recipient,
				string.Empty);

			switch (e.SplitArgs[1]) {
				case "eval":
					if (e.SplitArgs.Count < 3) {
						response.Message = "Not enough parameters.";
						responseEvent.Result = response;
						DoCallback(responseEvent);
						Status = PluginStatus.Stopped;
						break;
					}

					Status = PluginStatus.Running;
					string evalArgs = e.SplitArgs.Count > 3 ?
						e.SplitArgs[2] + e.SplitArgs[3] : e.SplitArgs[2];

					try {
						response.Message = new Calculator().Evaluate(evalArgs).ToString(CultureInfo.CurrentCulture);
						responseEvent.Result = response;
						DoCallback(responseEvent);
					} catch (Exception ex) {
						response.Message = ex.Message;
						responseEvent.Result = response;
						DoCallback(responseEvent);
					}
					break;
				case "join":
					if (Program.Bot.Users.LastSeen.Access > 1)
						response.Message = "Insufficient permissions.";
					else if (e.SplitArgs.Count < 3)
						response.Message = "Insufficient parameters. Type 'eve help join' to view command's help index.";
					else if (!e.SplitArgs[2].StartsWith("#"))
						response.Message = "Channel name must start with '#'.";
					else if (Program.Bot.Channels.Get(e.SplitArgs[2].ToLower()) != null)
						response.Message = "I'm already in that channel.";

					if (!string.IsNullOrEmpty(response.Message)) {
						responseEvent.Result = response;
						DoCallback(responseEvent);
						return;
					}

					response.Target = string.Empty;
					response.Message = e.SplitArgs[2];
					response.Protocol = Protocols.JOIN;
					responseEvent.Result = response;
					DoCallback(responseEvent);
					break;
			}

			Status = PluginStatus.Stopped;
		}