Add project files.
This commit is contained in:
56
StartupEvents/OnUserJoin.cs
Normal file
56
StartupEvents/OnUserJoin.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using PluginManager.Others;
|
||||
using PluginManager.Interfaces;
|
||||
|
||||
public class OnUserJoin : DBEvent
|
||||
{
|
||||
public string name => "OnPlayerJoin";
|
||||
|
||||
public string description => "An event that is triggered when an user joins the server";
|
||||
|
||||
public async void Start(Discord.WebSocket.DiscordSocketClient client)
|
||||
{
|
||||
|
||||
string UtilsPath = Functions.dataFolder + "StartupEvents/";
|
||||
string ConfigFile = UtilsPath + "UserJoinEvent.txt";
|
||||
|
||||
System.IO.Directory.CreateDirectory(UtilsPath);
|
||||
|
||||
if (!System.IO.File.Exists(ConfigFile))
|
||||
{
|
||||
await System.IO.File.WriteAllTextAsync(ConfigFile,
|
||||
"Enabled=True\nEmbed=True\n" +
|
||||
"#Available placeholders:\n" +
|
||||
"#{user.Name} => Username of the user\n" +
|
||||
"#{time.date} => Current Date\n" +
|
||||
"#{time.time} => Current time (hh:mm::ss)\n" +
|
||||
"MessageTitle = Welcome {user.Name}\n" +
|
||||
"MessageDescription=Embed description\n" +
|
||||
"MessageField1Title=Custom Title\n" +
|
||||
"MessageFiled1Text=Custom Filed 1 text\n" +
|
||||
"MessageField2Title=Custom Title\n" +
|
||||
"MessageFiled2Text=Custom Filed 2 text\n" +
|
||||
"MessageFooter=Today: {time.date} at {time.time}");
|
||||
}
|
||||
|
||||
if (Functions.readCodeFromFile(ConfigFile, "Enabled", '=') != "True") return;
|
||||
|
||||
client.UserJoined += async (user) =>
|
||||
{
|
||||
Discord.EmbedBuilder embed = new Discord.EmbedBuilder
|
||||
{
|
||||
Title = Functions.readCodeFromFile(ConfigFile, "MessageTitle", '='),
|
||||
Description = Functions.readCodeFromFile(ConfigFile, "MessageDescription", '=')
|
||||
};
|
||||
|
||||
embed
|
||||
.AddField(Functions.readCodeFromFile(ConfigFile, "MessageField1Title", '=').Replace("{user.Name}", user.Username).Replace("{time.date}", System.DateTime.Now.ToShortDateString()).Replace("{time.time}", System.DateTime.Now.ToShortTimeString()), Functions.readCodeFromFile(ConfigFile, "MessageField1Text", '=').Replace("{user.Name}", user.Username).Replace("{time.date}", System.DateTime.Now.ToShortDateString()).Replace("{time.time}", System.DateTime.Now.ToShortTimeString()))
|
||||
.AddField(Functions.readCodeFromFile(ConfigFile, "MessageField2Title", '=').Replace("{user.Name}", user.Username).Replace("{time.date}", System.DateTime.Now.ToShortDateString()).Replace("{time.time}", System.DateTime.Now.ToShortTimeString()), Functions.readCodeFromFile(ConfigFile, "MessageField2Text", '=').Replace("{user.Name}", user.Username).Replace("{time.date}", System.DateTime.Now.ToShortDateString()).Replace("{time.time}", System.DateTime.Now.ToShortTimeString()))
|
||||
.WithFooter(Functions.readCodeFromFile(ConfigFile, "MessageFooter", '=').Replace("{user.Name}", user.Username).Replace("{time.date}", System.DateTime.Now.ToShortDateString()).Replace("{time.time}", System.DateTime.Now.ToShortTimeString()));
|
||||
|
||||
await user.Guild.DefaultChannel.SendMessageAsync(embed: embed.Build());
|
||||
// await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync(embed: embed.Build());
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
48
StartupEvents/SetGameOnLogin.cs
Normal file
48
StartupEvents/SetGameOnLogin.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
public class SetGameOnLogin : PluginManager.Interfaces.DBEvent
|
||||
{
|
||||
public string name => "Set Game on Startup";
|
||||
public string description => "Set Custom Game to the bot at initialization";
|
||||
public async void Start(Discord.WebSocket.DiscordSocketClient client)
|
||||
{
|
||||
string UtilsPath = PluginManager.Others.Functions.dataFolder + "StartupEvents/";
|
||||
string ConfigFile = UtilsPath + "LoginEvent.txt";
|
||||
|
||||
System.IO.Directory.CreateDirectory(UtilsPath);
|
||||
if (!System.IO.File.Exists(ConfigFile))
|
||||
{
|
||||
System.Console.WriteLine($"First time setup. Open file: {ConfigFile} to change settings or use the following commands\nNote: For space ( ) use underline (_). Example: 'Hello_World' will output 'Hello World'");
|
||||
System.Console.WriteLine($"set-setting StartupEvents.LoginEvent.Title [Custom_Title(s)]");
|
||||
System.Console.WriteLine($"set-setting StartupEvents.LoginEvent.Dynamic_Title [True/False]");
|
||||
System.Console.WriteLine($"set-setting StartupEvents.LoginEvent.Dynamic_Title_Change_Rate [interval in milliseconds]");
|
||||
await System.IO.File.WriteAllTextAsync(ConfigFile, "Enabled=True\n\nDynamic Title=False\n#For dynamic title add titles like this:\n#Title=Hello,World,Test,Test2\nTitle=!help\nDynamic Title Change Rate=3500\n");
|
||||
}
|
||||
|
||||
if (PluginManager.Others.Functions.readCodeFromFile(ConfigFile, "Enabled", '=') != "True")
|
||||
return;
|
||||
|
||||
bool isDynamic = PluginManager.Others.Functions.readCodeFromFile(ConfigFile, "Dynamic Title", '=') == "True";
|
||||
string Title = PluginManager.Others.Functions.readCodeFromFile(ConfigFile, "Title", '=');
|
||||
if (Title == null || Title.Length < 2) return;
|
||||
if (!isDynamic)
|
||||
await client.SetGameAsync(Title, null, Discord.ActivityType.Playing);
|
||||
else
|
||||
{
|
||||
string[] Titles = Title.Split(',');
|
||||
int delayMS = 3500;
|
||||
try
|
||||
{
|
||||
delayMS = int.Parse(PluginManager.Others.Functions.readCodeFromFile(ConfigFile, "Dynamic Title Change Rate", '='));
|
||||
}
|
||||
catch { }
|
||||
while (true)
|
||||
{
|
||||
foreach (var title in Titles)
|
||||
{
|
||||
await client.SetGameAsync(title, null, Discord.ActivityType.Playing);
|
||||
await System.Threading.Tasks.Task.Delay(delayMS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
17
StartupEvents/StartupEvents.csproj
Normal file
17
StartupEvents/StartupEvents.csproj
Normal file
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<OutputPath>E:\DiscordBot\BUILDS\</OutputPath>
|
||||
<DebugType>none</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PluginManager\PluginManager.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user