0% found this document useful (0 votes)
6 views21 pages

Message

The document contains a series of command functions for a bot, including commands for welcoming users, managing duels, and displaying leaderboards. It features logic for rolling dice, sorting duel results, and managing user permissions. The code is structured to handle various user inputs and commands while providing feedback through embedded messages.

Uploaded by

hatr626
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views21 pages

Message

The document contains a series of command functions for a bot, including commands for welcoming users, managing duels, and displaying leaderboards. It features logic for rolling dice, sorting duel results, and managing user permissions. The code is structured to handle various user inputs and commands while providing feedback through embedded messages.

Uploaded by

hatr626
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 21

[Command("welcome")]

void WelcomeCommand(string user)


{
SendEmbed("Добро пожаловать на сервер авторов, "+ user +"!\nЧтобы привязать
свой тайтл, необходимо написать в этот чат:\n!title {ссылка на твой тайтл}");
}

[Command("l")]
void LegendCommand(int ring, int skill)
{
string answer = "";

for ( int i = 0; i < ring; i++){


string dice = "";
switch(Random(1,7))
{
case 1: dice = "-"; break;
case 2: dice = "<:ring4:1383415946466820126> <:ring2:1383415942838751363>";
break;
case 3: dice = "<:ring4:1383415946466820126>"; break;
case 4: dice = "<:ring1:1383415944751087667> <:ring2:1383415942838751363>";
break;
case 5: dice = "<:ring1:1383415944751087667>"; break;
case 6: dice = "<:ring3:1383415948484018247> <:ring2:1383415942838751363>";
break;
default: dice = "error";
}
answer += $"Выпало {dice}\n";

answer += "\n";

for ( int i = 0; i < skill; i++)


{

string dice = "";


switch(Random(1,13))
{
case 1:
case 2: dice ="-"; break;
case 3:
case 4:
case 5: dice = "<:ring4:1383415946466820126>"; break;
case 6:
case 7: dice = "<:ring1:1383415944751087667> <:ring2:1383415942838751363>";
break;
case 8:
case 9: dice = "<:ring1:1383415944751087667> "; break;
case 10: dice = "<:ring1:1383415944751087667> <:ring4:1383415946466820126>";
break;
case 11: dice = "<:ring3:1383415948484018247> <:ring2:1383415942838751363>";
break;
case 12: dice = "<:ring3:1383415948484018247>"; break;
default: dice = "error";
}
answer += $"Выпало {dice}\n"; }

SendEmbed(answer);
}

[Command("hatr")]
void HatrCommand(string command)
{
if(ULongParse("1093565773986926653") == GetUserId() ||
ULongParse("388430602703208449") == GetUserId()) {
try {
if(command == "view")
{
SendEmbed(GetArg("duel_ids"));
}
else if(command == "clear")
{
// SetArg("duel_ids", "");
}
else if(command == "sort")
{
string idsCsv = GetArg("duel_ids");

string[] raw_ids = idsCsv.Split(',');

string[] ids = new string[raw_ids.Length];


int[] losses = new int[raw_ids.Length];
int[] wins = new int[raw_ids.Length];

for (int i = 0; i < raw_ids.Length; i++)


{
string[] part = Split(raw_ids[i], ':');

ids[i] = part[0];

string[] scores = Split(part[1], '\\');

if (scores.Length == 2)
{
wins[i] = IntParse(scores[0]);
losses[i] = IntParse(scores[1]);
}
else
{
wins[i] = 0;
losses_[i] = 0;
}
}

QuickSort(ids, wins, losses, 0, ids.Length - 1);

void QuickSort(string[] ids, int[] wins, int[] losses, int left,


int right)
{
int i = left, j = right;

int pivotIndex = left + (right - left) / 2;


int pivotScore = wins[pivotIndex] - losses[pivotIndex] / 3;

while (i <= j)
{
while (wins[i] - losses[i] / 3 > pivotScore) i++;

while (wins[j] - losses[j] / 3 < pivotScore) j--;

if (i <= j)
{
Swap(ids, wins, losses, i, j);
i++;
j--;
}
}

if (left < j) QuickSort(ids, wins, losses, left, j);


if (i < right) QuickSort(ids, wins, losses, i, right);
}

void Swap(string[] ids, int[] wins, int[] losses, int a, int b)


{
// id
var tmpId = ids[a]; ids[a] = ids[b]; ids[b] = tmpId;
// wins
var tmpWins = wins[a]; wins[a] = wins[b]; wins[b] = tmpWins;
// losses
var tmpLoss = losses[a]; losses[a] = losses[b]; losses[b] =
tmpLoss;
}

string[] parts = new string[ids.Length];


for (int i = 0; i < ids.Length; i++)
{

parts[i] = $"{ids[i]}: {wins[i]}\\{losses[i]}";


}

string result = Join(parts, ",");

SetArg("duel_ids", result);
SendEmbed("finished");
}
}
catch(ex) {
SendEmbed("error: " + ex);
}
}
else {
SendEmbed($"Ты бесправная немощь");
}
}

[Command("HatrLog")]
void HatrLongCommand(string command, string command2)
{
if (ULongParse("1093565773986926653") == GetUserId() ||
ULongParse("388430602703208449") == GetUserId())
{
Log();
if (command == "view")
{
LeaderboardCommand(command2);
}

}
else
{
SendEmbed($"Ты бесправная немощь");
}
}

// duels

[Command("duels")]
void AddDuelsCommand(string command, string id, int wins, int losses)
{
try {
if(ULongParse("628202991085813783") != GetUserId()) {
SendEmbed("Ты бесправная немощь");
return;
}

AddDuels(command, id, wins, losses);


}
catch(ex) {
SendEmbed(ex);
}
}

void AddDuels(string command, string id, int wins, int losses, string idsCsv =
"empty")
{
try {
if(ULongParse("628202991085813783") != GetUserId()) {
SendEmbed("Ты бесправная немощь");
return;
}

try
{
if(idsCsv == "empty")
{
idsCsv = GetArg("duel_ids");
}
}
catch(ex)
{
}

if(command == "create" || command == "c")


{

if (idsCsv == null || idsCsv == "")


{
print("idsCsv is empty");
SetArg("duel_ids", id + ": " + wins + "\\" + losses);
}
else
{
string[] raw_ids = idsCsv.Split(',');

string[] ids = new string[raw_ids.Length];


int[] losses_ = new int[raw_ids.Length];
int[] wins_ = new int[raw_ids.Length];

for (int i = 0; i < raw_ids.Length; i++)


{
string[] part = Split(raw_ids[i], ':');

ids[i] = part[0];

string[] scores = Split(part[1], '\\');

if (scores.Length == 2)
{
wins_[i] = IntParse(scores[0]);
losses_[i] = IntParse(scores[1]);
}
else
{
wins_[i] = 0;
losses_[i] = 0;
}
}

bool contains = IndexOf(ids, id) != -1;

if (contains)
{
AddDuels(command, id, wins, losses, RemoveDuels("remove", id,
idsCsv));
return;
}
else {
raw_ids = raw_ids.AddAt(IndexTOAddToSorted_id(ids, wins_, losses_,
id, wins, losses), id + ": " + wins + "\\" + losses);
print("start SetArg");
SetArg("duel_ids", Join(raw_ids, ","));
print("finished SetArg");
}
}
SendEmbed($"{id} **{wins}**\\**{losses}**");
}
else if(command == "add" || command == "a")
{
if (idsCsv == null || idsCsv == "")
{
print("idsCsv is empty");
SendEmbed("протри глаза - в команде ошибка");
}
else
{
string[] raw_ids = idsCsv.Split(',');
string[] ids = new string[raw_ids.Length];
int[] losses_ = new int[raw_ids.Length];
int[] wins_ = new int[raw_ids.Length];

for (int i = 0; i < raw_ids.Length; i++)


{
string[] part = Split(raw_ids[i], ':');

ids[i] = part[0];

string[] scores = Split(part[1], '\\');

if (scores.Length == 2)
{
wins_[i] = IntParse(scores[0]);
losses_[i] = IntParse(scores[1]);
}
else
{
wins_[i] = 0;
losses_[i] = 0;
}
}

int idx = IndexOf(ids, id);


bool contains = idx != -1;

if (contains)
{
wins += wins_[idx];
print("wins_ " + wins_[idx]);
losses += losses_[idx];
print("losses_ " + wins_[idx]);

AddDuels("c", id, wins, losses, RemoveDuels("remove", id, idsCsv));


return;
}
else {
raw_ids = raw_ids.AddAt(IndexTOAddToSorted_id(ids, wins_, losses_,
id, wins, losses), id + ": " + wins + "\\" + losses);
print("start SetArg");
SetArg("duel_ids", Join(raw_ids, ","));
print("finished SetArg");
}
}
SendEmbed($"{id} **{wins}**\\**{losses}**");
}

}
catch(ex) {SendEmbed(ex);}

int IndexTOAddToSorted_id(string[] ids, int[] wins_, int[] losses_, string id, int
wins, int losses)
{
print("started IndexTOAddToSorted_id");
int score = (int)(wins - losses / 3);
int low = 0;
int high = ids.Length;
try{
while (low < high)
{
int mid = (low + high) / 2;
print($"start while low: {low} mid:{mid} idsLen {ids.Length}");
string other = ids[mid];
int otherWins = wins_[mid];
int otherLosses = losses_[mid];
int otherScore = otherWins - otherLosses;

if (score > otherScore)


high = mid;
else
low = mid + 1;

print("finished");
}
}catch(e){print("Sort cicle: "+e);}
return low;
}

string RemoveDuels(string command, string id, string idsCsv = "empty") {


try {
if(command == "remove" || command == "r")
{
print("started GetArg");
if(idsCsv == "empty")
{
idsCsv = GetArg("duel_ids");
}
print("finished GetArg");

if (idsCsv != null && idsCsv != "")


{
string[] raw_ids = idsCsv.Split(',');

string[] ids = new string[raw_ids.Length];

for (int i = 0; i < raw_ids.Length; i++)


{
string[] part = Split(raw_ids[i], ':');

ids[i] = part[0];
}

int idx = IndexOf(ids, id);

if (idx != -1)
{
print("started RemoveAt");
print($"before raw_ids length: {raw_ids.Length}");
raw_ids = raw_ids.RemoveAt(idx);
print($"after raw_ids length: {raw_ids.Length}");
print("finished RemoveAt");
}
else {
throw Exception("not found");
}

print("started SetArg");
if (raw_ids.Length != 0)
{
return Join(raw_ids, ",");
}
else {
return "";
}
}
}
}
catch(ex) {
SendEmbed(ex);
}
}

[Command("duels")]
void RemoveDuelsCommand(string command, string id)
{
try {
if(ULongParse("628202991085813783") != GetUserId()) {
SendEmbed("Ты бесправная немощь");
return;
}

if(command == "remove" || command == "r")


{
SetArg("duel_ids", RemoveDuels(command, id));

SendEmbed($"success");
}
}
catch(ex) {
SendEmbed(ex);
}
}

[Command("l")]
void LeaderboardCommand_(string command)
{
LeaderboardCommand(command);
}

[Command("leaderboard")]
void LeaderboardCommand(string command)
{
try {
if (command == "duel" || command == "duels")
{
var msg = SendEmbed(Leaderboard_duels(0, 10));
var component = GetComponent();

component.WithButton(">", "leaf_duels", "next,20");

msg.ModifyMessage(component);

}
else if (command == "judg" || command == "judges")
{
print("started judges command");

var msg = SendEmbed(Leaderboard_judges(0, 10));


print("finished SendEmbed(Leaderboard_judges(0, 10));");

var component = GetComponent();


print("finished GetComponent();");

component.WithButton(">", "leaf_judges", "next,20");

print("finished components");

msg.ModifyMessage(component);

print("msg.ModifyMessage(component); ");

}
}
catch(ex) {
SendEmbed(ex);
}
}

string Leaderboard_duels(int start, int end)


{
string idsCsv = GetArg("duel_ids");

if (idsCsv != "")
{
string[] raw_ids = idsCsv.Split(',');

Free(&idsCsv);

string[] ids = new string[raw_ids.Length];


int[] losses_ = new int[raw_ids.Length];
int[] wins_ = new int[raw_ids.Length];

for (int i = 0; i < raw_ids.Length; i++)


{
string[] part = Split(raw_ids[i], ':');

ids[i] = part[0];

string[] scores = Split(part[1], '\\');

if (scores.Length == 2)
{
wins_[i] = IntParse(scores[0]);
losses_[i] = IntParse(scores[1]);
}
else
{
wins_[i] = 0;
losses_[i] = 0;
}
}
Free(raw_ids);
string[] output = new string[end - start + 1];
output[0] = $"Рейтинг дуэлей (Победы/поражения)\nместа по {start}-{end}\n\
n";

print("started for");
for(int i = start; i < ids.Length && i < end && i > -1; i++) {
print(i);
output[i - start + 1] = i + 1 + ": " + ids[i] + ": " + wins_[i] + "\\"
+ losses_[i] + "\n";
}
print("finished for");

Free(ids);
Free(losses_);
Free(wins_);

return Join(output, "");


}
return "null";
}

[Button("leaf_duels")]
void ButtonFunction()
{
try {
Defer(); //признаем взаимодействие
string raw_arg = GetArgs();
string[] arg = Split(raw_arg, ',');
int next = IntParse(arg[1]);

if(arg[0] == "next") {
var component = GetComponent();

component.WithButton("<", "leaf_duels", $"previous,{next}");


component.WithButton(">", "leaf_duels", $"next,{next + 10}");

ModifyThis(Leaderboard_duels(next - 10, next), component);


}
else if(arg[0] == "previous") {
var component = GetComponent();

if(next - 10 > 0)
{
component.WithButton("<", "leaf_duels", $"previous,{next - 10}");
}

component.WithButton(">", "leaf_duels", $"next,{next}");

ModifyThis(Leaderboard_duels(next - 10, next), component);


}
else {
ModifyThis($"button error: {arg[0]}");
}
}
catch(ex) {
ModifyThis($"button error: " +GetMemoryUsage() + "\n" + GetMemoryDump(3000));
}

///
// judges

[Command("judges")]
void AddJudgesCommand(string command, string id, int score_1, int score_2, int
score_3)
{
try {
if(ULongParse("628202991085813783") != GetUserId()) {
SendEmbed("Ты бесправная немощь");
return;
}

AddJudges(command, id, score_1, score_2, score_3);


}
catch(ex) {
SendEmbed(ex);
}
}

void AddJudges(string command, string id, int score_1, int score_2, int score_3,
string idsCsv = "empty")
{
try {
try
{
if (idsCsv == "empty")
{
idsCsv = GetArg("judges_ids");
}
else
{
print("idsCsv is not empty: " + idsCsv);
}
}
catch (ex)
{
}

if(command == "create" || command == "c")


{

if (idsCsv == null || idsCsv == "")


{
print("idsCsv is empty");
SetArg("judges_ids", id + ": " + score_1 + "\\" + score_2 + "\\" +
score_3);
}
else
{
string[] raw_ids = idsCsv.Split(',');

string[] ids = new string[raw_ids.Length];

int[] score1 = new int[raw_ids.Length];


int[] score2 = new int[raw_ids.Length];
int[] score3 = new int[raw_ids.Length];

for (int i = 0; i < raw_ids.Length; i++)


{
string[] part = Split(raw_ids[i], ':');

ids[i] = part[0];

string[] scores = Split(part[1], '\\');

if (scores.Length == 3)
{
score1[i] = IntParse(scores[0]);
score2[i] = IntParse(scores[1]);
score3[i] = IntParse(scores[2]);
}
else
{
score1[i] = 0;
score2[i] = 0;
score3[i] = 0;
}
}

bool contains = IndexOf(ids, id) != -1;

if (contains)
{
AddJudges(command, id, score_1, score_2, score_3,
RemoveJudges("remove", id, idsCsv));
return;
}
else {
raw_ids = raw_ids.AddAt(IndexTOAddToSorted_id(ids, id, score1,
score2, score3, score_1 + score_2 + score_3), id + ": " + score_1 + "\\" + score_2
+ "\\" + score_3);
print("start SetArg");
SetArg("judges_ids", Join(raw_ids, ","));
print("finished SetArg");
}
}
SendEmbed($"{id} **{score_1}\\{score_2}\\{score_3}**");
}
else if(command == "add" || command == "a")
{
if (idsCsv == null || idsCsv == "")
{
print("idsCsv is empty");
SendEmbed("протри глаза - в команде ошибка");
}
else
{
string[] raw_ids = idsCsv.Split(',');

string[] ids = new string[raw_ids.Length];

int[] score1 = new int[raw_ids.Length];


int[] score2 = new int[raw_ids.Length];
int[] score3 = new int[raw_ids.Length];

for (int i = 0; i < raw_ids.Length; i++)


{
string[] part = Split(raw_ids[i], ':');

ids[i] = part[0];

string[] scores = Split(part[1], '\\');

if (scores.Length == 3)
{
score1[i] = IntParse(scores[0]);
score2[i] = IntParse(scores[1]);
score3[i] = IntParse(scores[2]);
}
else
{
score1[i] = 0;
score2[i] = 0;
score3[i] = 0;
}
}

int idx = IndexOf(ids, id);

bool contains = idx != -1;

if (contains)
{
score_1 += score1[idx];
score_2 += score2[idx];
score_3 += score3[idx];

print("score1 " + score1[idx]);


print("score2 " + score2[idx]);
print("score3 " + score3[idx]);

AddJudges("c", id, score_1, score_2, score_3,


RemoveJudges("remove", id, idsCsv));
return;
}
else {
raw_ids = raw_ids.AddAt(IndexTOAddToSorted_id(ids, id, score1,
score2, score3, score_1 + score_2 + score_3), id + ": " + score_1 + "\\" + score_2
+ "\\" + score_3);
print("start SetArg");
SetArg("judges_ids", Join(raw_ids, ","));
print("finished SetArg");
}
}
SendEmbed($"{id} **{score_1}**\\**{score_2}**\\**{score_3}**");
}

}
catch(ex) {SendEmbed(ex);}
}

int IndexTOAddToSorted_id(string[] ids, string id, int[] score1, int[] score2,


int[] score3, int score)
{
print("started IndexTOAddToSorted_id");

int low = 0;
int high = ids.Length;
try{
while (low < high)
{
int mid = (low + high) / 2;
print($"start while low: {low} mid:{mid} idsLen {ids.Length}");
string other = ids[mid];
int otherScore = score1[mid] + score2[mid] + score3[mid];

if (score > otherScore)


high = mid;
else
low = mid + 1;

print("finished");
}
}catch(e){print("Sort cicle: "+e);}
return low;
}

string RemoveJudges(string command, string id, string idsCsv = "empty") {


try {
if(command == "remove" || command == "r")
{
if(idsCsv == "empty")
{
idsCsv = GetArg("judges_ids");
}
else {
print("idsCsv is not empty: " + idsCsv);
}

if (idsCsv != null && idsCsv != "")


{
string[] raw_ids = idsCsv.Split(',');

string[] ids = new string[raw_ids.Length];

for (int i = 0; i < raw_ids.Length; i++)


{
string[] part = Split(raw_ids[i], ':');

ids[i] = part[0];
}

int idx = IndexOf(ids, id);

if (idx != -1)
{
print("started RemoveAt");
print($"before raw_ids length: {raw_ids.Length}");
raw_ids = raw_ids.RemoveAt(idx);
print($"after raw_ids length: {raw_ids.Length}");
print("finished RemoveAt");
}
else
{
throw Exception("not found");
}

if (raw_ids.Length != 0)
{
return Join(raw_ids, ",");
}
else
{
return "";
}
}
}
}
catch(ex) {
SendEmbed(ex);
}
}

[Command("judges")]
void RemoveJudgesCommand(string command, string id)
{
try
{
if (ULongParse("628202991085813783") != GetUserId())
{
SendEmbed("Ты бесправная немощь");
return;
}

if (command == "remove" || command == "r")


{
SetArg("judges_ids", RemoveJudges(command, id));

SendEmbed($"success");
}
}
catch (ex)
{
SendEmbed(ex);
}
}

string Leaderboard_judges(int start, int end)


{
string idsCsv = GetArg("judges_ids");

if (idsCsv != "")
{
string[] raw_ids = idsCsv.Split(',');

string[] ids = new string[raw_ids.Length];


int[] score1 = new int[raw_ids.Length];
int[] score2 = new int[raw_ids.Length];
int[] score3 = new int[raw_ids.Length];

for (int i = 0; i < raw_ids.Length; i++)


{
string[] part = Split(raw_ids[i], ':');

ids[i] = part[0];

string[] scores = Split(part[1], '\\');

if (scores.Length == 3)
{
score1[i] = IntParse(scores[0]);
score2[i] = IntParse(scores[1]);
score3[i] = IntParse(scores[2]);
}
else
{
score1[i] = 0;
score2[i] = 0;
score3[i] = 0;
}
}

string[] output = new string[end - start + 1];

output[0] = $"Рейтинг дуэлей (Дуэли/Монарх Акаши/Сокровище Акаши)\nместа по


{start}-{end}\n\n";

for(int i = start; i < ids.Length && i < end && i > -1; i++) {

output[i - start + 1] = i + 1 + ": " + ids[i] + ": " + score1[i] + " \\


" + score2[i] + " \\ " + score3[i];
}

return Join(output, "\n");


}
return "null";
}

[Button("leaf_judges")]
void ButtonFunction()
{
try {
Defer(); //признаем взаимодействие
string raw_arg = GetArgs();
string[] arg = Split(raw_arg, ',');
int next = IntParse(arg[1]);

if (arg[0] == "next")
{
print("started next if");
var component = GetComponent();

component.WithButton("<", "leaf_judges", $"previous,{next}");


component.WithButton(">", "leaf_judges", $"next,{next + 10}");
ModifyThis(Leaderboard_judges(next - 10, next), component);
print("fineshed next if");
}
else if (arg[0] == "previous")
{
print("started previous if");
var component = GetComponent();

if(next - 10 > 0)
{
component.WithButton("<", "leaf_judges", $"previous,{next - 10}");
}

component.WithButton(">", "leaf_judges", $"next,{next}");

ModifyThis(Leaderboard_judges(next - 10, next), component);


print("fineshed previous if");
}
else
{
ModifyThis($"button error: {arg[0]}");
}
}
catch(ex) {
ModifyThis($"button error: " + ex);
}
}

[Command("c")]
void TradeCommand(string id, int amount)
{
if(ULongParse("628202991085813783") == GetUserId() ||
ULongParse("1093565773986926653") == GetUserId()) {
if(!BalanceAdd(id, amount)) {
SendEmbed("нудачно, скорее всего баланс уходил в минус.");
}
else {
SendEmbed("успешно.");
}
}
}

[Command("casino")]
void CasinoCommand()
{
/*
string raw = GetArg("casino_balance");

string[] balance = Split(raw, ':');

int[] balance_ = new int[2];

balance_[0] = IntParse(balance[0]);
balance_[1] = IntParse(balance[1]);
*/

string embedText = $" **Добро пожаловать в Казино «Fortune Wheel»!** \n \


**Как играть**: \n \
• !casino lottery — покупка билета, стоииость 1к \n \
• !buy ticket N — покупка билета \n \
• !casino balance - посмотреть свой баланс \n \
\n Удачи!";

SendEmbed(embedText);
}

[Command("buy")]
void CasinoCommand(string type)
{
string playerID = "<@" + GetUserId() + ">";

if(type == "t1"){
TicketAdd(playerID, 1, 1);
}
}
[Command("casino")]
void CasinoCommand(string command)
{
if(command == "lottery" || command == "l") {
int playerBalance = 1000;

if(playerBalance >= 1000)


{
SendEmbed(CasinoLottery());
}
else {
SendEmbed("нищий брысь отсюда!");
return;
}
}
else if(command == "balance" || command == "b") {
string raw = "0";
string playerID = "<@" + GetUserId() + ">";

try {
raw = GetArg(playerID + "_balance");
}
catch(ex) {

string[] balance = Split(raw, ':');

int[] balance_ = new int[7];

for(int i = 0; i < balance.Length && i < balance_.Length; i++) {


balance_[i] = IntParse(balance[i]);
}

SendEmbed($"Ваш баланс монет: {balance_[0]} \n \


Билелетов тип1: {balance_[1]} \n \
Билелетов тип2: {balance_[2]} \n \
Билелетов тип3: {balance_[3]} \n \
Билелетов тип4: {balance_[4]} \n \
Билелетов тип5: {balance_[5]} \n \
Билелетов тип6: {balance_[6]} \n");
}
}

string CasinoLottery() {
int num1 = Random(0, 100);
int num2 = Random(0, 100);
int num3 = Random(0, 100);

string text = $"


**Ваш Лотерейный Билет** \n \
\n \
**Счастливые числа:** \n \
{num1} | {num2} | {num3} \n \
\n 🍀 **Желаем удачи!**";

return text;
}

bool TicketAdd(string id, int type, int num) {


string raw = "";

if(type <= 0 || type >= 7) {


throw Exception("Неверные параметры");
}

try {
raw = GetArg(id + "_balance");
}
catch(ex) {

string[] balance = Split(raw, ':');

int[] balance_ = new int[7];

for(int i = 0; i < balance.Length && i < balance_.Length; i++) {


balance_[i] = IntParse(balance[i]);
}

if(balance_[type] + num >= 0) {


balance_[type] += num;
}
else {
return false;
}

SetArg(id + "_balance", Join(balance_, ':'));

return true;
}

bool BalanceAdd(string id, int amount) {


string raw = "";

try {
raw = GetArg(id + "_balance");
}
catch(ex) {
}

if(raw != "") {
string[] balance = Split(raw, ':');

int[] balance_ = new int[7];

for(int i = 0; i < balance.Length && i < balance_.Length; i++) {


balance_[i] = IntParse(balance[i]);
}

if(balance_[0] + amount >= 0) {


balance_[0] += amount;
}
else { return false; }

SetArg(id + "_balance", Join(balance_, ':'));


}
else {
if(amount <= 0) { return false; }

SetArg(id + "_balance", $"{amount}:0:0:0:0:0:0");


}

return true;
}

[Command("coinflip")]
void CoinFlipCommand(int ticket, bool isTail) {
string playerID = "<@" + GetUserId() + ">";

if(!TicketAdd(playerID, ticket, -1)) {


SendEmbed("Недостаточно билетов.");
return;
}

int rd = Random(0, 100);


bool resultIsTail = false;

if(rd < 45) {}


else if(rd < 90) {
resultIsTail = true;
}
else {
SendEmbed("монетка потерялась... \n \
вы потеряли ставку");
return;
}

if(isTail == resultIsTail) {
SendEmbed("поздравляем! Вы выйграли X монет.");
//добавить в балнс
}
else {
SendEmbed("Неудача, попробуйте снова...");
}
}
[Command("coinflip")]
void CoinFlipInfo(string command)
{
if(command == "info" || command == "i") {
string info = $"🎲 Информация о команде !coinflip \n \
Игра «Орел и Решка с риском» \n \
\n \
Стоимость: 1 билет за игру \n \
Шансы: \n \
• Орел: 45% \n \
• Решка: 45% \n \
• Монетка потерялась: 10% \n \
\n \
Победа: НАДО ДОБАВИТЬ ЧТО-ТО \n \
Поражение или потеря монеты: ставка сгорает";

SendEmbed(info);
}
}

You might also like