-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonglist.cs
115 lines (102 loc) · 4.53 KB
/
songlist.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.Threading;
using System.IO;
using System.Windows.Forms;
namespace RutonyChat
{
// Script based on the internal Rutony CreditsQty which are associated with tickets.
// 1 ticket = 1 song, the quantity can be adjusted on line 87
public class Script
{
public void RunScript(string site, string username, string text, string param)
{
string Text_NotNumber = "{0}, the input must be a number!";
string Text_NumberNotInList = "Number {0}: request song is not in the songlist!";
string Text_AlreadyInList = "{0}, song is already in the request list or was already on stream!";
string Text_SuccessfullyAdded = "{0}, request <{1}> added.";
string Text_NoTickets = "{0}, you don't have enough tickets!";
string Text_ToManyArguments = "{0}, please request only a song from the songlist!";
// edit here the path to the file
string FileName_Source = @"C:\edit-here-path-to-file\songlist.txt";
string FileName_Requests = @"C:\edit-here-path-to-file\request.txt";
string FileName_Requests_Stream = @"C:\edit-here-path-to-file\request_stream.txt";
string[] arrText = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if(arrText.Length > 2)
{
// if user writes more arguments then needed
RutonyBot.BotSay(site, string.Format(Text_ToManyArguments, username));
return;
}
int songnumber = 0;
// check, if via command and is number
if(arrText.Length == 1)
{
if (int.TryParse(arrText[0], out songnumber) == false)
{
RutonyBot.BotSay(site, string.Format(Text_NotNumber, username));
return;
}
}
//check, if via sr and is number
else if(arrText.Length == 2)
{
if (int.TryParse(arrText[1], out songnumber) == false)
{
RutonyBot.BotSay(site, string.Format(Text_NotNumber, username));
return;
}
}
// read the count of lines in songlist
int songnumbers = RutonyBotFunctions.FileLength(FileName_Source);
// if greater then number of songs, exit
if(songnumbers < songnumber)
{
RutonyBot.BotSay(site, string.Format(Text_NumberNotInList, songnumber));
return;
}
string songname = RutonyBotFunctions.FileStringAt(FileName_Source, songnumber-1);
string request = username + " - " + songname;
// if already exist in request list, exit
if (FileHasString(FileName_Requests_Stream, songname))
{
RutonyBot.BotSay(site, string.Format(Text_AlreadyInList, username));
return;
}
// get user
RankControl.ChatterRank cr = RankControl.ListChatters.Find(r => r.Nickname == username.Trim().ToLower());
if (cr != null)
{
// add to request song list, if credits are greater 0
if(cr.CreditsQty > 0)
{
RutonyBotFunctions.FileAddString(FileName_Requests, request);
RutonyBotFunctions.FileAddString(FileName_Requests_Stream, songname);
RutonyBot.BotSay(site, string.Format(Text_SuccessfullyAdded, username, request));
// reduce the number of tickets by 1
cr.CreditsQty -= 1;
} else {
RutonyBot.BotSay(site, string.Format(Text_NoTickets, username));
}
}
}
private bool FileHasString(string filename, string text)
{
try
{
string[] lines = File.ReadAllLines(filename);
foreach (string strLine in lines)
{
if (strLine.Contains(text))
{
return true;
}
}
} catch
{
return false;
}
return false;
}
}
}