mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-25 22:06:34 +00:00
added initial version containing ping/echo command and first draft of the command handling structure
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package dev.sheldan.abstracto;
|
||||
|
||||
import dev.sheldan.abstracto.service.StartupManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = "dev.sheldan.abstracto")
|
||||
@EnableCaching
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private StartupManager startup;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
startup.startBot();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package dev.sheldan.abstracto.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
@Builder
|
||||
public class Channel {
|
||||
|
||||
@Id
|
||||
@Getter
|
||||
public Long id;
|
||||
|
||||
@Getter
|
||||
@ManyToMany(mappedBy = "channels")
|
||||
private Set<ChannelGroup> groups;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package dev.sheldan.abstracto.models;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class ChannelGroup {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Getter
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
@Getter @Setter
|
||||
private String groupName;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "channel_in_group",
|
||||
joinColumns = @JoinColumn(name = "group_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "channel_id"))
|
||||
@Getter
|
||||
private Set<Channel> channels;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package dev.sheldan.abstracto.models;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class PostTarget {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Getter
|
||||
private Long id;
|
||||
|
||||
@Column(unique = true)
|
||||
@Getter
|
||||
private String name;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY, optional = false)
|
||||
@JoinColumn(name = "id", nullable = false)
|
||||
@Getter
|
||||
private Channel channel;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package dev.sheldan.abstracto.models;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class Role {
|
||||
|
||||
@Id
|
||||
@Getter
|
||||
private Long id;
|
||||
|
||||
@Column(unique = true)
|
||||
@Getter @Setter
|
||||
private String name;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.sheldan.abstracto.repository;
|
||||
|
||||
import dev.sheldan.abstracto.models.Channel;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ChannelRepository extends JpaRepository<Channel, Long> {
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package dev.sheldan.abstracto.service;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
@Service
|
||||
public class BotService implements Bot {
|
||||
|
||||
private JDA instance;
|
||||
|
||||
@Override
|
||||
public void login() throws LoginException {
|
||||
JDABuilder builder = new JDABuilder(System.getenv("TOKEN"));
|
||||
|
||||
builder.setDisabledCacheFlags(EnumSet.of(CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE));
|
||||
builder.setBulkDeleteSplittingEnabled(false);
|
||||
|
||||
this.instance = builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JDA getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package dev.sheldan.abstracto.service;
|
||||
|
||||
import dev.sheldan.abstracto.commands.management.CommandReceivedHandler;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class StartupManager implements Startup {
|
||||
|
||||
@Autowired
|
||||
private BotService service;
|
||||
|
||||
@Autowired
|
||||
private List<? extends ListenerAdapter> listeners;
|
||||
|
||||
@Override
|
||||
public void startBot() throws LoginException {
|
||||
service.login();
|
||||
listeners.forEach(o -> service.getInstance().addEventListener(o));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/abstracto
|
||||
spring.datasource.username= abstracto
|
||||
spring.datasource.password= abstracto
|
||||
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
|
||||
spring.jpa.hibernate.ddl-auto = update
|
||||
Reference in New Issue
Block a user