Added Timer and Enabled multiple attributes on Methods.

This commit is contained in:
Dultus 2023-06-27 16:48:43 +02:00
parent b1cf263ba4
commit 88eae830f2
2 changed files with 34 additions and 4 deletions

View file

@ -60,12 +60,15 @@ namespace Discord.Controller
{
methods.AddRange(type.GetMethods());
}
EventControllerAttribute<T>? attribute;
List<EventControllerAttribute<T>>? attribute;
foreach (var method in methods)
{
attribute = method.GetCustomAttribute<EventControllerAttribute<T>>();
if (attribute is not null && EqualityComparer<T>.Default.Equals(attribute.Event, category))
method.Invoke(null, new object[] { ids, e });
attribute = method.GetCustomAttributes<EventControllerAttribute<T>>().ToList();
foreach (var attr in attribute)
{
if (EqualityComparer<T>.Default.Equals(attr.Event, category))
method.Invoke(null, new object[] { ids, e });
}
}
}
}

27
Discord/Helpers/Timer.cs Normal file
View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Discord.Helpers
{
internal class Timer
{
private System.Threading.Timer? timer;
public void SetUpTimer(TimeSpan alertTime,object passingObject, Action<object> method)
{
DateTime current = DateTime.Now;
TimeSpan timeToGo = alertTime - current.TimeOfDay;
if (timeToGo < TimeSpan.Zero)
{
return;//time already passed
}
this.timer = new System.Threading.Timer(x =>
{
method.Invoke(passingObject);
}, null, timeToGo, Timeout.InfiniteTimeSpan);
}
}
}