Add git, restructure
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
using Godot;
|
||||
using LibGit2Sharp;
|
||||
using LibGit2Sharp.Handlers;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
public partial class GitIntigration:Node{
|
||||
[Export] Button commit_button;
|
||||
[Export] Window options_window;
|
||||
[Export] Node Main;
|
||||
[Export] Label Push_error;
|
||||
[Export] Control Push_Base;
|
||||
[Export] Button pull_button;
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
commit_button.Pressed += Commit_changes;
|
||||
pull_button.Pressed += pull;
|
||||
Button edit = (Button)options_window.Get("clone_repo_button");
|
||||
if (edit != null){
|
||||
edit.Pressed += Clone;
|
||||
}
|
||||
Button reset_button = (Button)options_window.Get("reset_repo_button");
|
||||
if (reset_button != null){
|
||||
reset_button.Pressed += reset;
|
||||
}
|
||||
}
|
||||
|
||||
void delete_recursive(String path){
|
||||
Godot.DirAccess current_access = Godot.DirAccess.Open(path);
|
||||
current_access.IncludeHidden = true;
|
||||
foreach (String Dir in current_access.GetDirectories()){
|
||||
//GD.Print("found " + path.PathJoin(Dir));
|
||||
delete_recursive(path.PathJoin(Dir));
|
||||
}
|
||||
foreach (String file in current_access.GetFiles()){
|
||||
//GD.Print("found file " + file);
|
||||
current_access.Remove(file);
|
||||
}
|
||||
DirAccess.RemoveAbsolute(path);
|
||||
}
|
||||
|
||||
public void Clone(){
|
||||
Label edit = (Label)options_window.Get("clone_log");
|
||||
string path = ProjectSettings.GlobalizePath("user://repo/");
|
||||
if (Godot.DirAccess.DirExistsAbsolute(path)){
|
||||
GD.Print("ADAD");
|
||||
delete_recursive(path);
|
||||
DirAccess.RemoveAbsolute(path);
|
||||
}
|
||||
try {
|
||||
Repository.Clone(get_repo(), path);
|
||||
}
|
||||
catch(Exception e){
|
||||
GD.Print("Cloning failed, " + e.Message);
|
||||
if (edit != null){
|
||||
edit.Text = "Cloning failed, " + e.Message;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (edit != null){
|
||||
edit.Text = "Success! Repo cloned at: " + path;
|
||||
}
|
||||
Main.CallDeferred("set_file",path+"blacklist.txt");
|
||||
}
|
||||
|
||||
String get_repo(){
|
||||
LineEdit edit = (LineEdit)options_window.Get("repo_edit");
|
||||
if (edit != null){
|
||||
return edit.Text;
|
||||
}
|
||||
else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String get_email(){
|
||||
LineEdit edit = (LineEdit)options_window.Get("email_edit");
|
||||
if (edit != null){
|
||||
return edit.Text;
|
||||
}
|
||||
else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String get_name(){
|
||||
LineEdit edit = (LineEdit)options_window.Get("name_edit");
|
||||
if (edit != null){
|
||||
return edit.Text;
|
||||
}
|
||||
else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String get_key(){
|
||||
LineEdit edit = (LineEdit)options_window.Get("key_edit");
|
||||
if (edit != null){
|
||||
return edit.Text;
|
||||
}
|
||||
else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void pull(){
|
||||
|
||||
string path = ProjectSettings.GlobalizePath("user://repo/");
|
||||
Repository repo = new Repository(path);
|
||||
// Credential information to fetch
|
||||
LibGit2Sharp.PullOptions options = new LibGit2Sharp.PullOptions();
|
||||
options.MergeOptions = new MergeOptions();
|
||||
options.MergeOptions.CommitOnSuccess = true;
|
||||
options.MergeOptions.FileConflictStrategy = CheckoutFileConflictStrategy.Ours;
|
||||
options.FetchOptions = new FetchOptions();
|
||||
options.FetchOptions.CredentialsProvider = new CredentialsHandler(
|
||||
(url, usernameFromUrl, types) =>
|
||||
new UsernamePasswordCredentials()
|
||||
{
|
||||
Username = get_name(),
|
||||
Password = get_key()
|
||||
});
|
||||
|
||||
// User information to create a merge commit
|
||||
var signature = new LibGit2Sharp.Signature(
|
||||
new Identity(get_name(), get_email()), DateTimeOffset.Now);
|
||||
|
||||
// Pull
|
||||
try{
|
||||
Commands.Pull(repo, signature, options);
|
||||
}
|
||||
catch(Exception e){
|
||||
Push_error.Text = e.Message;
|
||||
Push_Base.Show();
|
||||
return;
|
||||
}
|
||||
Main.CallDeferred("set_file",path+"blacklist.txt");
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
GD.Print("Reset");
|
||||
string path = ProjectSettings.GlobalizePath("user://repo/");
|
||||
Repository repo = new Repository(path);
|
||||
Branch originMain = repo.Branches["origin/main"];
|
||||
repo.Reset(ResetMode.Hard, originMain.Tip);
|
||||
Main.CallDeferred("set_file",path+"blacklist.txt");
|
||||
}
|
||||
|
||||
public void Commit_changes(){
|
||||
string path = ProjectSettings.GlobalizePath("user://repo");
|
||||
GD.Print("Try commit");
|
||||
Repository repo = new Repository(path);
|
||||
repo.Index.Add("blacklist.txt");
|
||||
repo.Index.Write();
|
||||
Signature author = new Signature(get_name(), get_email(), DateTime.Now);
|
||||
Signature committer = author;
|
||||
try{
|
||||
Commit commit = repo.Commit("Update Banlist", author, committer);
|
||||
}
|
||||
catch(Exception e){
|
||||
Push_error.Text = e.Message;
|
||||
Push_Base.Show();
|
||||
return;
|
||||
}
|
||||
|
||||
LibGit2Sharp.PushOptions options = new LibGit2Sharp.PushOptions();
|
||||
options.CredentialsProvider = new CredentialsHandler(
|
||||
(url, usernameFromUrl, types) =>
|
||||
new UsernamePasswordCredentials()
|
||||
{
|
||||
Username = get_name(),
|
||||
Password = get_key()
|
||||
});
|
||||
try{
|
||||
repo.Network.Push(repo.Branches["main"], options);
|
||||
}
|
||||
catch(Exception e){
|
||||
Push_error.Text = e.Message;
|
||||
Push_Base.Show();
|
||||
return;
|
||||
}
|
||||
|
||||
//repo.Commit("Update banlist");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dv74d87a31oyx
|
||||
@@ -0,0 +1,6 @@
|
||||
class_name altshowcase extends Control
|
||||
|
||||
@export var name_label: Label
|
||||
@export var uid_label: Label
|
||||
@export var count_label: Label
|
||||
@export var search_alts_button: Button
|
||||
@@ -0,0 +1 @@
|
||||
uid://2f384phq5272
|
||||
@@ -0,0 +1,10 @@
|
||||
class_name Punishment extends Resource
|
||||
|
||||
@export var username:String = ""
|
||||
@export var uid:String = ""
|
||||
@export var what_punishment:punishment_types
|
||||
@export var punish_reason:String = ""
|
||||
## in unix time, zero means forever
|
||||
@export var punish_end:int
|
||||
|
||||
enum punishment_types{BAN,MUTE}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cafyno407e2uq
|
||||
@@ -0,0 +1,36 @@
|
||||
class_name BanListExporter extends Node
|
||||
|
||||
func Export(Punishments:Array[Punishment],file:String) -> void:
|
||||
var fileaccess:FileAccess = FileAccess.open(file,FileAccess.WRITE)
|
||||
if !fileaccess:
|
||||
push_error("!fileaccess is true")
|
||||
return
|
||||
var content:String = ""
|
||||
content += "L!ListBegin\n"
|
||||
for punishment in Punishments:
|
||||
if !punishment.username:
|
||||
continue
|
||||
content += "NAME: " + punishment.username + "\n"
|
||||
content += "UID: " + punishment.uid + "\n"
|
||||
content += "PUNISHMENT: " + ("MUTE" if punishment.what_punishment ==
|
||||
punishment.punishment_types.MUTE else "BAN") + "\n"
|
||||
content += "REASON: " + punishment.punish_reason + "\n"
|
||||
content += "END_DATE: " + str(punishment.punish_end) + "\n"
|
||||
content += "L!ListEnd\n"
|
||||
|
||||
fileaccess.store_string(content)
|
||||
|
||||
func Exportv1(Punishments:Array[Punishment],file:String) -> void:
|
||||
var fileaccess:FileAccess = FileAccess.open(file,FileAccess.WRITE)
|
||||
if !fileaccess:
|
||||
push_error("!fileaccess is true")
|
||||
return
|
||||
var content:String = ""
|
||||
content += "L!ListBegin\n"
|
||||
for punishment in Punishments:
|
||||
if !punishment.username:
|
||||
continue
|
||||
content += "NAME: " + punishment.username + "\n"
|
||||
content += "UID: " + punishment.uid + "\n"
|
||||
content += "L!ListEnd\n"
|
||||
fileaccess.store_string(content)
|
||||
@@ -0,0 +1 @@
|
||||
uid://caaljvxo8tja5
|
||||
@@ -0,0 +1,205 @@
|
||||
class_name mainNode extends Control
|
||||
@export var edit_window:EditWindow
|
||||
@export var punish_list_parser: PunishListParser
|
||||
@export var PunishContainer:Control
|
||||
@export var punish_scene:PackedScene
|
||||
@export var new_punish_btn:Button
|
||||
@export var file_opener:FileDialog
|
||||
@export var open_btn:Button
|
||||
@export var new_btn:Button
|
||||
@export var save_btn:Button
|
||||
@export var exporter:BanListExporter
|
||||
@export var file_label:Label
|
||||
@export var save_file_parser:SaveFileParser
|
||||
@export var quit_confirmation:ConfirmationDialog
|
||||
@export var ban_counter: Label
|
||||
@export var save_label: Label
|
||||
@export var plus: CPUParticles2D
|
||||
@export var minus: CPUParticles2D
|
||||
@export var more_btn: Button
|
||||
@export var options_window: MoreOptionsWindow
|
||||
|
||||
var current_path:String
|
||||
var unsaved:bool
|
||||
|
||||
func _ready() -> void:
|
||||
more_btn.pressed.connect(options_window.show)
|
||||
edit_window.changed.connect(update_ban_counter) # use as update
|
||||
|
||||
var save_file = save_file_parser.read()
|
||||
quit_confirmation.canceled.connect(get_tree().quit)
|
||||
quit_confirmation.confirmed.connect(save_and_exit)
|
||||
get_tree().auto_accept_quit = false
|
||||
get_tree().root.close_requested.connect(close_request)
|
||||
set_file(save_file.get("FILE",""))
|
||||
file_opener.file_selected.connect(set_file)
|
||||
open_btn.pressed.connect(file_opener.show)
|
||||
new_btn.pressed.connect(new_punishment)
|
||||
save_btn.pressed.connect(save)
|
||||
options_window.remove_dupes.connect(remove_dupes)
|
||||
options_window.save_v_one.connect(savevone)
|
||||
|
||||
options_window.repo_edit.text = save_file.get("REPO","")
|
||||
options_window.email_edit.text = save_file.get("EMAIL","")
|
||||
options_window.name_edit.text = save_file.get("NAME","")
|
||||
options_window.key_edit.text = save_file.get("KEY","")
|
||||
options_window.use_old.button_pressed = save_file.get("USE_OLD",false)
|
||||
|
||||
options_window.repo_edit.text_changed.connect(unsave.unbind(1))
|
||||
options_window.email_edit.text_changed.connect(unsave.unbind(1))
|
||||
options_window.name_edit.text_changed.connect(unsave.unbind(1))
|
||||
options_window.key_edit.text_changed.connect(unsave.unbind(1))
|
||||
options_window.use_old.pressed.connect(unsave)
|
||||
|
||||
func unsave():
|
||||
save_label.show()
|
||||
unsaved = true
|
||||
|
||||
func savevone():
|
||||
var Punishments:Array[Punishment]
|
||||
for child in PunishContainer.get_children():
|
||||
if child is PunishShowcase:
|
||||
Punishments.append(child.punishment)
|
||||
exporter.Exportv1(Punishments,current_path.rstrip(".txt")+" v1.txt")
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if Input.is_action_just_pressed("save"):
|
||||
save()
|
||||
|
||||
var last_alts:int = 0
|
||||
func remove_dupes():
|
||||
unsaved = true
|
||||
remove_loop()
|
||||
update_ban_counter()
|
||||
|
||||
func remove_loop():
|
||||
var found:bool = remove_iteration()
|
||||
if found == true:
|
||||
remove_loop()
|
||||
|
||||
func remove_iteration() -> bool:
|
||||
var punishments:Array[PunishShowcase]
|
||||
for child in PunishContainer.get_children():
|
||||
if child is PunishShowcase:
|
||||
punishments.append(child)
|
||||
for punishment_keep in punishments:
|
||||
for punishment_two in punishments:
|
||||
# cancel if not same name
|
||||
if punishment_keep == punishment_two:
|
||||
continue
|
||||
if punishment_keep.punishment.username != punishment_two.punishment.username:
|
||||
continue
|
||||
# cancel if not same uid
|
||||
if punishment_keep.punishment.uid != punishment_two.punishment.uid:
|
||||
continue
|
||||
# if there a reason?
|
||||
if punishment_keep.punishment.punish_reason == "":
|
||||
punishment_keep.punishment.punish_reason = punishment_two.punishment.punish_reason
|
||||
# is there a time set?
|
||||
if punishment_keep.punishment.punish_end == 0:
|
||||
punishment_keep.punishment.punish_end = punishment_two.punishment.punish_end
|
||||
# if its a mute maybe it should be a ban
|
||||
if punishment_keep.punishment.what_punishment == Punishment.punishment_types.MUTE:
|
||||
punishment_keep.punishment.what_punishment = punishment_two.punishment.what_punishment
|
||||
|
||||
punishment_two.free()
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func update_ban_counter():
|
||||
var punishments:Array[Punishment]
|
||||
for child in PunishContainer.get_children():
|
||||
if child is PunishShowcase:
|
||||
punishments.append(child.punishment)
|
||||
var count:int = 0
|
||||
var keys:Array[String]
|
||||
for punishment in punishments:
|
||||
if punishment.uid != "":
|
||||
if !keys.has(punishment.uid):
|
||||
keys.append(punishment.uid)
|
||||
count += 1
|
||||
else:
|
||||
if !keys.has(punishment.username):
|
||||
keys.append(punishment.username)
|
||||
count += 1
|
||||
ban_counter.text = str(punishments.size()) + " Entires :::::: " + str(count) + \
|
||||
" Unique :::::: " + str(punishments.size()-count) + " Alts"
|
||||
var alts = punishments.size() - count
|
||||
if last_alts != alts:
|
||||
if alts > last_alts:
|
||||
plus.emitting = true
|
||||
else:
|
||||
minus.emitting = true
|
||||
last_alts = alts
|
||||
|
||||
func save():
|
||||
save_label.hide()
|
||||
var Punishments:Array[Punishment]
|
||||
for child in PunishContainer.get_children():
|
||||
if child is PunishShowcase:
|
||||
Punishments.append(child.punishment)
|
||||
update_ban_counter()
|
||||
save_file_parser.save(current_path)
|
||||
if options_window.use_old.button_pressed:
|
||||
exporter.Exportv1(Punishments,current_path)
|
||||
else:
|
||||
exporter.Export(Punishments,current_path)
|
||||
unsaved = false
|
||||
|
||||
func new_punishment() -> void:
|
||||
unsaved = true
|
||||
save_label.show()
|
||||
var child:PunishShowcase = punish_scene.instantiate()
|
||||
child.punishment = Punishment.new()
|
||||
PunishContainer.add_child(child)
|
||||
child.update()
|
||||
child.Edit.connect(edit_called)
|
||||
edit_called(child,true)
|
||||
update_ban_counter()
|
||||
|
||||
func add_punishments(file:String):
|
||||
save_label.show()
|
||||
var punishments = punish_list_parser.parse(file)
|
||||
for punish:Punishment in punishments:
|
||||
var child:PunishShowcase = punish_scene.instantiate()
|
||||
child.punishment = punish
|
||||
PunishContainer.add_child(child)
|
||||
child.update()
|
||||
child.Edit.connect(edit_called)
|
||||
update_ban_counter()
|
||||
|
||||
func clear_children():
|
||||
save_label.hide()
|
||||
for child in PunishContainer.get_children():
|
||||
print("kill ",child)
|
||||
child.queue_free()
|
||||
update_ban_counter.call_deferred()
|
||||
|
||||
func edit_called(on:PunishShowcase,set_time:bool = false):
|
||||
save_label.show()
|
||||
unsaved = true
|
||||
edit_window.opened_from = on
|
||||
edit_window.punishment = on.punishment if on else Punishment.new()
|
||||
edit_window.update(set_time)
|
||||
edit_window.show()
|
||||
edit_window.grab_focus()
|
||||
update_ban_counter()
|
||||
|
||||
func set_file(path:String):
|
||||
clear_children()
|
||||
print("buh")
|
||||
current_path = path
|
||||
file_label.text = path
|
||||
add_punishments(path)
|
||||
update_ban_counter.call_deferred()
|
||||
|
||||
func close_request():
|
||||
if !unsaved:
|
||||
get_tree().quit()
|
||||
else:
|
||||
quit_confirmation.show()
|
||||
|
||||
func save_and_exit():
|
||||
save()
|
||||
get_tree().quit()
|
||||
@@ -0,0 +1 @@
|
||||
uid://c57yqopmolu8o
|
||||
@@ -0,0 +1,49 @@
|
||||
class_name PunishListParser extends Node
|
||||
|
||||
func parse(file:String) -> Array[Punishment]:
|
||||
if !file:
|
||||
return []
|
||||
var fileaccess:FileAccess = FileAccess.open(file,FileAccess.READ)
|
||||
if fileaccess == null:
|
||||
printerr("no access to file: fileaccess == null")
|
||||
return []
|
||||
var raw:String = fileaccess.get_as_text()
|
||||
var lines:PackedStringArray = raw.split("\n")
|
||||
var punishments:Array[Punishment]
|
||||
var formatting:bool = false
|
||||
for line in lines:
|
||||
var splits:PackedStringArray = line.split(": ")
|
||||
if line.contains(":") and !line.contains(": "):
|
||||
push_error("WARNING, INCORRECT FORMATTING")
|
||||
formatting = true
|
||||
splits = line.split(":")
|
||||
match splits[0]:
|
||||
"L!ListBegin":
|
||||
print("start")
|
||||
"NAME":
|
||||
var new_punish:Punishment = Punishment.new()
|
||||
new_punish.username = splits[1]
|
||||
punishments.append(new_punish)
|
||||
"UID":
|
||||
punishments[-1].uid = splits[1]
|
||||
"PUNISHMENT":
|
||||
var punish:Punishment.punishment_types = punish_text_to_enum(splits[1])
|
||||
punishments[-1].what_punishment = punish
|
||||
"REASON":
|
||||
punishments[-1].punish_reason = splits[1]
|
||||
"END_DATE":
|
||||
punishments[-1].punish_end = splits[1].to_int()
|
||||
"L!ListEnd":
|
||||
break
|
||||
if formatting:
|
||||
OS.alert("This file contains incorret formatting, things might not load correctly!")
|
||||
return punishments
|
||||
|
||||
func punish_text_to_enum(text) -> Punishment.punishment_types:
|
||||
var punish:Punishment.punishment_types
|
||||
match text:
|
||||
"BAN":
|
||||
punish = Punishment.punishment_types.BAN
|
||||
"MUTE":
|
||||
punish = Punishment.punishment_types.MUTE
|
||||
return punish
|
||||
@@ -0,0 +1 @@
|
||||
uid://c5ihhdkosauvw
|
||||
@@ -0,0 +1,27 @@
|
||||
class_name SaveFileParser extends Node
|
||||
@export var options_window: MoreOptionsWindow
|
||||
|
||||
const savloc = "user://save.dat"
|
||||
|
||||
func read() -> Dictionary:
|
||||
var file = FileAccess.open(savloc,FileAccess.READ)
|
||||
if !file:
|
||||
print("no savefile found")
|
||||
return {}
|
||||
var Dict:Dictionary = file.get_var()
|
||||
return Dict
|
||||
|
||||
func save(current_file:String) -> void:
|
||||
var file = FileAccess.open(savloc,FileAccess.WRITE)
|
||||
if !file:
|
||||
push_error("cant write savefile")
|
||||
return
|
||||
var Dict:Dictionary[String,Variant] = {
|
||||
"FILE":current_file,
|
||||
"REPO":options_window.repo_edit.text,
|
||||
"EMAIL":options_window.email_edit.text,
|
||||
"NAME":options_window.name_edit.text,
|
||||
"KEY":options_window.key_edit.text,
|
||||
"USE_OLD":options_window.use_old.button_pressed,
|
||||
}
|
||||
file.store_var(Dict)
|
||||
@@ -0,0 +1 @@
|
||||
uid://3gmapu83dglo
|
||||
@@ -0,0 +1,37 @@
|
||||
extends Node
|
||||
|
||||
@export var search_bar:LineEdit
|
||||
@export var punish_container:Node
|
||||
@export var name_check: CheckButton
|
||||
@export var uid_check: CheckButton
|
||||
@export var description_check: CheckButton
|
||||
|
||||
func _ready() -> void:
|
||||
search_bar.text_changed.connect(update.unbind(1))
|
||||
name_check.toggled.connect(update.unbind(1))
|
||||
uid_check.toggled.connect(update.unbind(1))
|
||||
description_check.toggled.connect(update.unbind(1))
|
||||
|
||||
func update():
|
||||
var text = search_bar.text
|
||||
print("ss")
|
||||
if text:
|
||||
for child in punish_container.get_children():
|
||||
child.hide()
|
||||
var strings:PackedStringArray = text.split(";")
|
||||
for child in punish_container.get_children():
|
||||
if child is PunishShowcase:
|
||||
var valid:bool = true
|
||||
for string in strings:
|
||||
if string:
|
||||
var in_name:bool = (string.to_lower() in child.name_label.text.to_lower()) if name_check.button_pressed else false
|
||||
var in_uid:bool = (string.to_lower() in child.uid_label.text.to_lower()) if uid_check.button_pressed else false
|
||||
var in_decsciption:bool = (string.to_lower() in child.punishment.punish_reason.to_lower()) if description_check.button_pressed else false
|
||||
if !in_name and !in_uid and !in_decsciption:
|
||||
valid = false
|
||||
if valid:
|
||||
child.show()
|
||||
else:
|
||||
for child in punish_container.get_children():
|
||||
if child is PunishShowcase:
|
||||
child.show()
|
||||
@@ -0,0 +1 @@
|
||||
uid://bt5wd8qjaevk0
|
||||
Reference in New Issue
Block a user